Skip to content
Latchkey

How to Pass a Build Output to a Deploy Job in GitHub Actions

Build once, upload the output as an artifact, then download it in a deploy job so you never rebuild to ship.

Upload the compiled output in the build job, add needs: build on the deploy job, and download the same artifact before deploying.

Steps

  • Upload the build output as a named artifact in the build job.
  • Set needs: build on the deploy job.
  • Download the artifact, then run the deploy command.

Workflow

.github/workflows/ci.yml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - run: npm ci && npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist/
  deploy:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: dist
          path: dist/
      - run: ./deploy.sh dist/

Gotchas

  • The deploy job runs on a fresh runner, so nothing survives except the downloaded artifact.
  • Building once and reusing the artifact avoids "works on build, breaks on deploy" drift.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →