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: buildon 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
How to Download an Artifact to a Specific Path in GitHub ActionsControl where a GitHub Actions artifact lands by setting the path input on actions/download-artifact@v4, rest…
How to Download an Artifact in the Same Workflow in GitHub ActionsDownload an artifact within the same GitHub Actions run using actions/download-artifact@v4, restoring files a…