Artifacts
Artifacts pass files between jobs in a workflow (or back to you for download). Build once, test the same artefact across matrices, then promote it to deploy.
Upload, download, retention, scope
EXAMPLE
# .github/workflows/build-test-deploy.yml
name: Build → Test → Deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: 20, cache: npm }
- run: npm ci
- run: npm run build # → dist/
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7 # default is 90
if-no-files-found: error
test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node: [18, 20, 22]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: ${{ matrix.node }} }
- uses: actions/download-artifact@v4
with: { name: dist, path: dist }
- run: npm ci
- run: npm test
- if: failure()
uses: actions/upload-artifact@v4
with:
name: traces-node-${{ matrix.node }}
path: test-results/
deploy:
needs: test
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with: { name: dist, path: dist }
- run: rsync -av dist/ deploy@host:/var/www/
Why it matters
Artifacts make “built once, tested everywhere” trivial. Without them, every job rebuilds — slower, racier, and you can ship a different artefact than you tested.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# Later job
- uses: actions/download-artifact@v4
with: { name: dist }
Try it Yourself »
Exercise
Upload a built directory between jobs.
uses: actions/
-artifact@v4
Six letters.
Discussion
Loading…