How to Set a Step Output in GitHub Actions
A step output is the canonical way to hand a single value to a later step in the same job.
Give the step an id, append name=value to $GITHUB_OUTPUT, then read steps.<id>.outputs.<name> downstream.
Steps
- Add an
id:to the step that computes the value. - Append
name=valueto$GITHUB_OUTPUT. - Reference
${{ steps.<id>.outputs.<name> }}in later steps.
Workflow
.github/workflows/ci.yml
steps:
- id: vars
run: |
echo "tag=$(git describe --tags --always)" >> "$GITHUB_OUTPUT"
- run: docker build -t myapp:${{ steps.vars.outputs.tag }} .Gotchas
- The legacy
::set-outputcommand is removed; use$GITHUB_OUTPUT. - To cross a job boundary, promote the step output to a job
outputs:entry.
Related guides
How to Pass Data Between Jobs in GitHub ActionsPass values between GitHub Actions jobs using job outputs and the needs context, wiring a step output up to a…
How to Share Environment Variables Across Steps in GitHub ActionsShare a value computed in one step with later steps in GitHub Actions by appending name=value to the GITHUB_E…