Interview Prep/Real-World Interview/Write-a-pipeline tasks

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.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-pipeline tasks