A hosted runner is thrown away when its job ends, and its files go with it. An artifact is a file or folder that you ask CI to keep, such as a compiled program or a test report.
Uploading
- run: |
mkdir -p dist
echo "version 1" > dist/app.txt
- uses: actions/upload-artifact@v7
with:
name: app
path: dist/
retention-days: 7name identifies the artifact within the run, and path says what to include. Artifacts expire. retention-days sets how long to keep this one, within the limits of your repository settings.
Passing files between jobs
Jobs do not share a disk, so a later job downloads the artifact:
check:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
name: app
path: dist
- run: cat dist/app.txtversion 1needs: build matters. Without it, check could start before the artifact exists.
This also gives you "build once, test and ship the same file". Rebuilding in every job can produce slightly different results.
Downloading to your computer
Use the run's page on GitHub, or the CLI:
gh run download 1234567890 --name app --dir downloadedUseful details
- With
upload-artifactv4 and later, two jobs cannot upload to the same artifact name in one run. In a matrix, include the matrix value in the name. - Hidden files are left out by default.
- File permissions such as the executable bit are not preserved. Put files in a
tararchive first if they matter. - Do not upload secrets, such as
.envfiles or private keys. People with access to the repository may download artifacts.
An artifact is not the same as a cache. A cache speeds up later runs by reusing things like downloaded dependencies, which can be recreated. An artifact is an output you want to keep or inspect.
Test reports are worth keeping even when tests fail. Add if: always() to the upload step so that an earlier failure does not skip it. The official documentation lists storage limits, which depend on your plan.
Try it
Practise the permissions workaround locally:
mkdir -p dist && printf '#!/bin/sh\necho hi\n' > dist/hi.sh
chmod +x dist/hi.sh
tar -czf dist.tar.gz dist
tar -tzvf dist.tar.gzThe listing shows the x bits stored in the archive. The search and archives lab has more tar practice.
Check your understanding
Build Artifacts
All 3 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.