Artifacts: Upload and Download Between Jobs
What you'll learn: How to share files and build outputs between jobs in GitHub Actions workflows using artifact upload and download actions.
Why Jobs Need to Share Files
In multi-job workflows, each job runs in a fresh, isolated environment. If Job A builds your application and creates a binary, and Job B needs to test that exact binary, you can't just reference it directly—the file is gone once Job A completes. Artifacts solve this by storing files temporarily so later jobs can retrieve them.
Think of artifacts like a shared locker at the gym: Job A finishes its workout (build), stores its belongings (build outputs) in the locker, and Job B can come by later with the key to grab them.
Uploading Artifacts
Use the actions/upload-artifact action to save files from a job:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Build application
run: make build
- name: Upload build output
uses: actions/upload-artifact@v3
with:
name: app-binary
path: dist/app
The name identifies your artifact, and path specifies what to store (files or directories).
Downloading Artifacts
Later jobs use actions/download-artifact to retrieve stored files:
test:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: app-binary
- name: Run tests
run: ./app --test
Artifacts are extracted into the current working directory by default. The needs: build ensures the test job waits for the build job to complete.
Key Takeaway: Use upload-artifact to save job outputs and download-artifact to retrieve them in dependent jobs, enabling seamless data sharing across your workflow's isolated execution environments.