Sub topic 11
Branching on Step Outputs and Outcomes
This chapter assumes you can read a workflow file, know that a job contains steps, and have used if: on a step. Here you will make one step decide whether a later step runs, either by writing an output or by reporting its own result.
Step outputs are strings
A step with an id can write name=value lines to the file named by $GITHUB_OUTPUT. Later steps read them through the steps context as steps.<id>.outputs.<name>.
Every output is a string. The text false is a non-empty string, and a non-empty string is truthy. A bare reference such as if: steps.check.outputs.extra therefore runs the step even when the output is false. Compare against the text instead.
steps:
- name: Decide whether to run extra checks
id: check
run: echo "extra=true" >> "$GITHUB_OUTPUT"
- name: Extra checks
if: steps.check.outputs.extra == 'true'
run: ./extra-checks.shThe comparison == 'true' matches the text, so it behaves the way you expect. If the output was never set, the expression reads an empty string and the comparison is false.
Outcome and conclusion
Every step with an id also exposes two result values.
| Value | Meaning |
|---|---|
| `steps.<id>.outcome` | The result before `continue-on-error` is applied. |
| `steps.<id>.conclusion` | The result after `continue-on-error` is applied. |
Both take one of these values: success, failure, cancelled, or skipped. The two differ only when a step fails and has continue-on-error: true. The outcome is failure, but the conclusion is success, so the job carries on.
This lets you tolerate a failure and still react to it.
steps:
- name: Lint
id: lint
continue-on-error: true
run: ./lint.sh
- name: Report lint problems
if: steps.lint.outcome == 'failure'
run: echo "Lint failed, but the build continues"Here the job does not fail because of lint. The second step still sees the original failure through outcome.
Combining outputs with status checks
A step condition that has no status function gets an implicit success(). If an earlier step failed, your output test never runs. To check an output after a failure, add a status function.
- name: Upload report
if: ${{ always() && steps.check.outputs.extra == 'true' }}
run: ./upload-report.shPut always() or failure() in the expression, joined with &&. Otherwise the implicit success() still applies.
Common mistakes
- Reading a step's output without giving the step an
id. The reference resolves to an empty string. - Comparing to a boolean, as in
== true. The output is the string'true', so quote it. - Using
outcomewhen you meantconclusion. Useconclusionto ask whether the job is still healthy. - Expecting an output from a step that was skipped. A skipped step writes nothing.
Exercise
A step with id scan writes found=false to $GITHUB_OUTPUT. A later step has if: steps.scan.outputs.found. Does it run, and how would you fix the condition?
Show answer
It runs, because false is a non-empty string and so is truthy. Change the condition to if: steps.scan.outputs.found == 'true'.
Exercise
A step build has continue-on-error: true and its command exits with an error. What are steps.build.outcome and steps.build.conclusion?
Show answer
The outcome is failure and the conclusion is success.