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.
More on GitHub Actions
What are workflows, jobs, steps and actions in GitHub Actions?BeginnerWhat events can trigger a workflow?BeginnerWhat is the difference between `pull_request` and `pull_request_target`?AdvancedWhat is a runner, and how do GitHub-hosted and self-hosted runners differ?BeginnerHow does a build matrix work?IntermediateWhat are reusable workflows and how do you call one?Intermediate