Interview Prep/CI/CD/GitHub Actions

How do you pass data between steps and between jobs?

IntermediateConceptGitHub Actions
Answer

Within a job, write to $GITHUB_OUTPUT and read it via the step id; set env for later steps with $GITHUB_ENV. Between jobs, declare outputs: on the job and read them through needs. Files travel via artifacts.

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.v.outputs.version }}
    steps:
      - id: v
        run: echo "version=1.4.${{ github.run_number }}" >> "$GITHUB_OUTPUT"
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploying ${{ needs.build.outputs.version }}"

The old ::set-output workflow command is deprecated in favour of $GITHUB_OUTPUT.

All CI/CD questions

More on GitHub Actions