GitHub Actions: Artifacts and Outputs

GitHub Actions: Artifacts and Outputs
"A job is a silo. Artifacts and Outputs are the bridges that allow data to flow through your factory."
In a professional pipeline, you have multiple Jobs.
- Job 1: Compiles your app into a
.zipfile. - Job 2: Deploys that
.zipfile to the server. The Problem: Job 2 has NO access to the files from Job 1. When Job 1 finishes, its computer is wiped clean.
Artifacts and Outputs solve this. They allow you to "Save" a file or a piece of text so other jobs can use it later. This 1,500+ word guide explores the "State Management" of your pipeline.
1. What are Artifacts? (The "Warehouse")
An Artifact is a Persisted File.
- Use Case: Storing a "PDF Report," a "Compiled Binary," or "Test Screenshots."
- Storage: GitHub stores these for 90 days (by default).
How to Upload:
- uses: actions/upload-artifact@v4
with:
name: compiled-app
path: build/out/How to Download (in a different job):
- uses: actions/download-artifact@v4
with:
name: compiled-app2. Job Outputs: The "Variable" Bridge
Sometimes you don't need a whole file; you just need a single word (e.g., a Version Number or a Docker Tag).
- The Strategy: One step calculates the value and "Sets" it as an output.
steps:
- id: step1
run: echo "tag=v1.2.3" >> $GITHUB_OUTPUT
outputs:
my_tag: ${{ steps.step1.outputs.tag }}Now, any other job in your file can access ${{ needs.my_job.outputs.my_tag }}.
3. The "Matrix" Data Flow
In $2026$, we use Matrix Builds (Module 114).
- If you build for Windows, Linux, and Mac simultaneously, you will have 3 different artifacts.
- You should name them uniquely:
app-windows,app-linux,app-macos. - Later, your "Release" job can download ALL of them and group them into one professional download page for your users.
4. Performance: Artifact Retention
GitHub gives you a "Quota" for storage.
- If you save $1$GB of artifacts for every single "Push," you will run out of space in one day.
- The Fix: Set
retention-days: 1for temporary build files, and only useretention-days: 90for the final "Release" binaries.
5. Security: Don't store Secrets in Artifacts
Artifacts are Public to anyone who can see your repo settings.
- The Warning: Never store
.envfiles or "Private Keys" as artifacts. Anyone can download them and see your password. - If you need to share a secret between jobs, use Encrypted Secrets (Module 119) or OIDC instead.
Summary: The Data Checklist
- Files vs Text: Use Artifacts for files; use Outputs for single variables.
- Naming: Be specific (
test-results-unitvstest-results-e2e). - Needs: Use the
needskeyword in YAML to ensure Job 2 waits for Job 1's outputs. - Retention: Keep your storage clean by setting short life-spans for temp artifacts.
- Security: Audit your artifacts gallery once a week to ensure no sensitive data is leaked.
Artifacts and Outputs are the "Nerves" of your CI/CD system. By mastering the persistence of files and the passing of variables, you gain the ability to build massive, multi-stage pipelines that are both perfectly organized and incredibly powerful. You graduate from "Running a script" to "Architecting a Factory."
Frequently Asked Questions
Q: What is a GitHub Actions artifact and how do you upload one?
An artifact is any file or directory produced during a workflow run that you want to persist beyond the job — build binaries, test reports, coverage files, or deployment packages. Upload with the actions/upload-artifact step: uses: actions/upload-artifact@v4 with name (artifact label) and path (file or glob). Artifacts are stored by GitHub for 90 days by default and can be downloaded from the Actions run summary page or by another job in the same workflow.
Q: How do you pass data between jobs in a GitHub Actions workflow?
Use job outputs for small scalar values: define outputs on the producing job with ${{ steps.step-id.outputs.value }}, then reference ${{ needs.job-id.outputs.value }} in the consuming job. For large files (binaries, reports), upload an artifact in the first job and download it with actions/download-artifact in the second job. Both approaches require needs: [job-id] to enforce execution order.
Q: What is the difference between artifacts and the GitHub Actions cache?
The cache (actions/cache) stores reusable data between workflow runs — node_modules, pip packages, compiled dependencies — to speed up future runs. Artifacts store the outputs of a specific run for download or use within that run. Cache entries are keyed and shared across branches; artifacts belong to a single run. Use cache for build dependencies, artifacts for build outputs and reports.
Part of the GitHub Mastery Course — engineering the flow.
