In GitHub Actions workflows, individual jobs execute in completely isolated runner virtual machines. Environment variables defined in one job are not available in downstream jobs. To pass data between jobs, you must export values using step outputs and declare them in job-level outputs.
Deprecation Warning: Avoid ::set-output
GitHub has officially deprecated and disabled the legacy ::set-output workflow command. Workflows attempting to execute echo "::set-output name=..." fail on modern GitHub runners. Always append output keys to the $GITHUB_OUTPUT environment file.
Correct Multi-Job Workflow Syntax
Passing variables between jobs requires a two-tiered mapping:
- Write the value to
$GITHUB_OUTPUTinside a step with anid. - Expose that step output in the job's top-level
outputsblock. - Declare
needs: <producer-job>in the downstream job and access the value vianeeds.<job>.outputs.<key>.
name: Cross-Job Variable Transfer
on: [push]
jobs:
build-and-generate:
runs-on: ubuntu-latest
outputs:
artifact-version: ${{ steps.version-step.outputs.version }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Compute Build Version
id: version-step
run: |
BUILD_TAG="v2.4.0-${{ github.run_number }}"
echo "Computed build tag: $BUILD_TAG"
# Modern GitHub Actions output assignment
echo "version=$BUILD_TAG" >> "$GITHUB_OUTPUT"
deploy-service:
runs-on: ubuntu-latest
needs: build-and-generate
steps:
- name: Consume Version from Upstream Job
run: |
echo "Deploying target version: ${{ needs.build-and-generate.outputs.artifact-version }}"

0 Comments