Cover photo by Wim Arys on Unsplash
I wanted a CI pipeline job to fail if some numeric output was larger than 0.
The pipeline is set up in Github Actions and the job has a step which has a numeric output. I just had to give an id
to the step to be able to reference it's outputs with Github Action contexts like:
${{ steps.stepId.outputs.outputName }}
The next step would check the output value, compare it to 0 and exit 1
if it is larger. Then I remembered steps (as well as jobs) have an if
section which takes in an expression. I knowe you no longer have to put ${{
& }}
around the expression but I wasn't sure if it would work simply like this:
if: steps.myStep.outputs.myOutput > 0
When I'm not sure of something, I like to test it. I often test pieces of Github Actions by making a new workflow, pushing it to master
and trying it out on Github.
Here is my workflow for testing how can a job's step output be used in an if
expression of a subsequent step:
I wanted to test it with different values so I used workflow_dispatch
's inputs to give my workflow a custom parameter for testing.
I ran the workflow with several numbers and confirmed it works.
I also found the answer on the Github forum, but it would have been nice if Github Actions documentation had some easy-to-reach example for this.
I could have also probably gotten the answer even faster from an LLM prompt.
In any case, it is nice to be able to test your code, wherever you got it from.
Edit: When you have your test workflow, no need to push it to master
& test it on Github. You can use act to test Github Action workflows locally.
Top comments (0)