AI Hints
CI/CD with GitHub Actions · Lesson 45 of 138

Job Outputs

Values across machines.

⏱ 2 min read▶ Video at 51:23🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Jobs run on different machines, so they can't share files or variables directly. If one job works out a version number, and another job needs it, you pass it as a job output.

Job Outputs
From the video: Job Outputs
  • Jobs are separate machines
  • Nothing shared directly
  • Job outputs

From one job to another

The version job has an outputs section. Its tag output takes the value of a step output. The build job needs version, and reads the value with needs dot version dot outputs dot tag. Here, the tag is made from the number of commits.

.github/workflows/versions.ymlyaml
name: Versions
on: push
jobs:
  version:
    runs-on: ubuntu-latest
    outputs:
      tag: ${{ steps.make.outputs.tag }}
    steps:
      - id: make
        run: echo "tag=v1.$(git rev-list --count HEAD).0" >> "$GITHUB_OUTPUT"
  build:
    needs: version
    runs-on: ubuntu-latest
    steps:
      - run: echo "Building image shop:${{ needs.version.outputs.tag }}"

The tag arrives

The version job writes the tag, v one point one point zero, because there's one commit. And the build job receives it, on what would be a completely different machine. That's how a pipeline can tag an image in one job, and deploy that same tag in another.

Terminal
run-steps .github/workflows/versions.yml
Workflow: Versions  (event: push, branch: main)
Job: version
  ✓ Run echo "tag=v1.$(git rev-list --count HEAD).0" >> "$GITHUB_OUTPUT"
  Job succeeded
Job: build
  ✓ Run echo "Building image shop:v1.1.0"
      Building image shop:v1.1.0
  Job succeeded

Summary

Job outputs pass values between jobs. Map a step output into the job's outputs, then read it with needs dot job dot outputs. Next, conditions.

Key takeaways
  • outputs: on the job
  • needs.job.outputs.name
  • Across machines
Next up: Conditions with if — run only when