Write a workflow that passes a value (image tag) from one job to another.
IntermediateHands-onWrite-a-pipeline tasks
Answer
jobs:
build:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.meta.outputs.tag }}
steps:
- id: meta
run: echo "tag=$(date +%Y%m%d)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- run: echo "Deploying ${{ needs.build.outputs.tag }}"
Key trick → Write name=value to $GITHUB_OUTPUT (the old ::set-output is deprecated), expose it as a job output, and read it with needs.<job>.outputs. Jobs run on separate machines, so files and environment variables don't carry over.
More on Write-a-pipeline tasks
Write a GitHub Actions workflow that runs tests on every PR and push to main.BeginnerWrite a workflow that builds a Docker image and pushes it to ECR using OIDC (no access keys).IntermediateWrite a matrix job that tests on Python 3.10, 3.11 and 3.12 on Linux and Windows.BeginnerWrite a declarative Jenkinsfile with build, test, Docker push and a manual approval before prod.AdvancedWrite a GitHub Actions deploy job that requires approval for production using environments.BeginnerWrite a reusable workflow and call it from another repo.Intermediate