Advanced Workflow PatternsLesson 5.4
How to pass data between steps using outputs in GitHub Actions
step outputs, GITHUB_OUTPUT, echo to output file, steps context, job outputs, passing job outputs to downstream jobs, output expressions
Step Outputs
Steps can emit named values that downstream steps in the same job consume via the steps context. This avoids writing temporary files and keeps pipelines clean.
Setting and Reading Outputs
steps:
- name: Get version
id: version
run: echo "tag=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
- name: Use version
run: echo "Deploying version ${{ steps.version.outputs.tag }}"Write to $GITHUB_OUTPUT using the key=value format. The step must have an id to be referenced. Access via steps.<id>.outputs.<key>.
Passing Outputs Between Jobs
jobs:
build:
outputs:
image-tag: ${{ steps.tag.outputs.tag }}
steps:
- id: tag
run: echo "tag=${{ github.sha }}" >> $GITHUB_OUTPUT
deploy:
needs: build
steps:
- run: echo "Image tag: ${{ needs.build.outputs.image-tag }}"Jobs expose outputs via the job-level outputs map. Downstream jobs access them via needs.<job-id>.outputs.<key>.
