How to publish artifacts in GitHub Actions?
· Category: DevOps & CI/CD
Short answer
Use actions/upload-artifact to save files from a workflow and actions/download-artifact to retrieve them in downstream jobs.
Steps
- Build or generate files in a job.
- Use
actions/upload-artifactto store them. - Use
actions/download-artifactin another job.
Example
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: build-output
- run: ./deploy.sh
Tips
- Artifact names must be unique within a workflow run.
- Use
retention-daysto control storage costs. - Large artifacts slow down upload and download times.
Common issues
- Artifact names are case-sensitive.
- Downloading an artifact that was not uploaded causes failure.
- Artifact storage has size and retention limits.