Sub topic 5
Naming Artifacts and Why v4 Artifacts Are Immutable
This chapter assumes you can read a workflow file and know that each job runs on its own runner. It also assumes you have already uploaded an artifact with actions/upload-artifact. Here you will learn how artifact names work and why version 4 of the upload and download actions changed the rules about reusing them.
The name is the artifact's identity
Every artifact in a workflow run has a name. The name is how a later step or job asks for it back. If you leave name out, the action uses the default, artifact.
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/A later job downloads this artifact by asking for name: dist. The name is also what you see in the run summary and what gh run download --name dist looks for. Pick names that describe the contents, such as dist, coverage-report, or test-logs.
What immutable means in v4
In actions/upload-artifact@v3 and earlier, several uploads could share one name. The artifact grew as each step added files to it. This was convenient, but it caused race conditions when parallel jobs wrote to the same artifact.
In v4, an artifact is immutable. Once an upload finishes, the artifact is sealed. You cannot add files to it, and you cannot upload a second artifact with the same name in the same run. The second upload fails with a conflict error.
That fence is only a placeholder in prose form, so here is the actual flow as a diagram.
Immutability gives you two benefits. Parallel jobs can no longer corrupt each other's files, and a download always returns exactly what was uploaded, with nothing added afterward.
The matrix problem
The most common way to hit the conflict is a matrix build. Each matrix job runs the same steps, so a fixed name collides.
# This fails: every matrix job tries to create "results"
- uses: actions/upload-artifact@v4
with:
name: results
path: results.txtThe fix is to put a value that differs per job into the name. Matrix values work well for this:
name: unique-names
on: push
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- run: echo "results for ${{ matrix.os }}" > results.txt
shell: bash
- uses: actions/upload-artifact@v4
with:
name: results-${{ matrix.os }}
path: results.txtThis run produces two artifacts, results-ubuntu-latest and results-windows-latest. A later chapter shows how to download them together.
A shared prefix such as results- is useful. It lets a download step select the whole group with a pattern like results-*.
Allowed characters
Artifact names are used in file paths and URLs, so some characters are rejected. Avoid these in names:
| Character | Example problem | Column | Column |
|---|---|---|---|
| Double quote `"` | `my"file` | ||
| Colon `:` | `build:linux` | ||
| Less than and greater than `<` `>` | `a<b` | ||
| Vertical bar `\ | ` | `x\ | y` |
| Asterisk and question mark `*` `?` | `results-*` | ||
| Backslash and slash `\` `/` | `linux/arm64` | ||
| Carriage return and line feed | Multi-line values |
A matrix value like a platform string linux/arm64 contains a slash, so it is not safe in a name. Replace it first, or use a matrix key that has no special characters.
Re-running and overwriting
Immutability applies within one run. When you re-run failed jobs, the earlier artifacts from that run still exist, so a re-uploaded name can conflict again. The upload action has an overwrite input for this case:
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
overwrite: trueWith overwrite: true, the action deletes the existing artifact of that name and uploads a new one. It does not append. Use it for re-runs, not as a way to build up an artifact in several steps.
Collecting files from several steps
Because you cannot append, gather everything into one upload step. Copy the files into one directory, then upload that directory once. If separate jobs produce the files, give each its own artifact and merge on download.
Exercise
A matrix job runs on three operating systems and each job uploads path: report.html with name: report. Two of the three jobs fail at the upload step. Why does this happen, and what is the smallest change that fixes it?
Show answer
In v4 artifacts are immutable and names must be unique within a run. The first job to finish creates report, and the other two uploads conflict with it. Change the name to include a matrix value, for example name: report-${{ matrix.os }}, so each job creates its own artifact.
Exercise
Why is name: build/${{ matrix.platform }} risky when matrix.platform is linux/arm64?
Show answer
The resulting name contains slashes, which are not allowed in artifact names. Use a value without special characters, such as linux-arm64.