Sub topic 6
Setting Retention and Handling Missing Files
This chapter assumes you can read a GitHub Actions workflow, know that jobs run on separate runners, and have already uploaded an artifact with actions/upload-artifact@v4. Here you will control how long an artifact is kept and what the upload step does when it finds nothing to upload.
How long artifacts live
Every artifact has a retention period. When it ends, GitHub deletes the artifact and it can no longer be downloaded by a job, the CLI, or the web UI.
The default is 90 days. Repository, organization, and enterprise settings can lower or raise that default, within limits set by the owner of the account. Private repositories can usually set a shorter maximum than public ones.
You can override the default for a single upload with retention-days:
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7Rules to remember:
- The value is a whole number of days, from 1 up to the maximum your repository allows.
- A value above the repository maximum is capped at that maximum. It does not cause an error.
retention-days: 0means "use the repository default", not "delete immediately".- The clock starts when the artifact is uploaded.
Choosing a value
Pick the shortest period that still serves the artifact's purpose.
| Artifact | Typical retention |
|---|---|
| Build output handed to a later job in the same run | 1 day |
| Test reports and logs used for debugging | 7 to 14 days |
| Release binaries you may need to re-publish | 30 to 90 days |
Short retention keeps storage use down. It also limits how long a file stays available if it contains something you did not intend to publish.
When no files match
The path input can match nothing. A typo, a failed build that wrote no output, or a different working directory can all cause this. The if-no-files-found input decides what happens.
| Value | Behavior |
|---|---|
| `warn` | The step succeeds and writes a warning. This is the default. |
| `error` | The step fails. |
| `ignore` | The step succeeds with no message. |
The default of warn is easy to miss. The job turns green, and the problem only appears later, when a download-artifact step reports that the artifact does not exist. For artifacts that later jobs depend on, set error so the failure appears at the step that caused it.
name: build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
if-no-files-found: errorThis job keeps dist for 7 days. If the build produced no files in dist/, the upload step fails and the run is marked as failed.
Choosing between the three values
ignore suits optional output. For example, a test run may write a crash dump only when something goes wrong, so its absence is normal.
Uploading when earlier steps fail
A related problem: by default, a step runs only if all earlier steps succeeded. If your tests fail, a plain upload step is skipped, and you lose the test report you most need.
Add if: always() to upload regardless of earlier results:
- run: npm test
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-report
path: reports/
retention-days: 14
if-no-files-found: warnHere warn is a reasonable choice. If the failure happened before any report was written, you do not want a second error hiding the first one.
Common mistakes
- Relying on the default
warnfor an artifact that a later job downloads. - Setting a long
retention-dayson every upload "just in case", which fills your storage quota. - Expecting
retention-daysto exceed the repository maximum. It is silently capped. - Forgetting
if: always(), so reports are missing exactly when tests fail. - Using
retention-days: 0expecting immediate deletion.
Exercise
Exercise
A build job uploads dist/ with default settings. The build step has a bug and writes its output to build/ instead. The job shows green, but the deploy job that downloads the dist artifact fails. Which input would have made the build job fail first, and which value should you set?
Show answer
Set if-no-files-found: error on the upload step. The default is warn, so the empty upload only produced a warning and the run continued. With error, the upload step fails at the source of the problem.
Exercise
You want test logs kept for two weeks and uploaded even when tests fail, without causing a second failure if no logs exist. Write the upload step's if condition and the two inputs you would set.
Show answer
Use if: always(), retention-days: 14, and if-no-files-found: warn (or ignore).