C.W.K.
Stream
Lesson 08 of 14 · published

Step Outputs

~10 min · outputs, steps, communication

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Pass values from one step to the next

A step can publish outputs that later steps in the same job can read. Outputs go to $GITHUB_OUTPUT; later steps reference them via steps.<id>.outputs.<name>.

How to write

Write key=value lines to $GITHUB_OUTPUT:

echo "sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT

For multi-line values, use the heredoc-style delimiter:

{
echo 'changelog<<EOF'
cat CHANGELOG.md
echo 'EOF'
} >> $GITHUB_OUTPUT

How to read

Reference by step id + output name. Example: steps.meta.outputs.sha.

Steps in different jobs can't read each other's outputs directly. Use job outputs (next lesson) for that.

Code

Step output — produce + consume·yaml
      - name: Compute version
        id: version
        run: |
          v=$(git describe --tags --always)
          echo "value=$v" >> $GITHUB_OUTPUT
          echo "short=${v#v}" >> $GITHUB_OUTPUT

      - name: Build with version
        run: |
          docker build -t myapp:${{ steps.version.outputs.short }} .

External links

Exercise

Write a job with three steps: compute a version string, write it to GITHUB_OUTPUT, and use it in a third step's tag/build command. Confirm the value flows correctly in the run logs.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.