Sub topic 11
Getting artifacts from the web UI and the GitHub CLI
This chapter assumes you can read a workflow file, know that each job runs on its own runner, and have already uploaded an artifact with actions/upload-artifact. Here you will retrieve those artifacts by hand, without writing a download step in a workflow.
When you need a manual download
Workflow downloads cover jobs that run in the same run or in a later run. Manual download covers people. You might want to open a test report, install a build on your own machine, or inspect the files from a failing run. Two tools cover this: the run page in the GitHub web UI and the GitHub CLI (gh).
Downloading from the web UI
- Open the repository on GitHub and select the Actions tab.
- Select the workflow in the left sidebar, then select a run.
- Scroll to the Artifacts section at the bottom of the run summary page.
- Select an artifact name to download it.
The browser downloads a ZIP file. The ZIP is named after the artifact, and the files inside keep the relative paths they had when they were uploaded. Unzip it to see the contents.
Artifacts only appear while they exist. After the retention period ends, the artifact is deleted and the Artifacts section no longer lists it. A run can also show an artifact that you cannot download if you only have read access to a repository that restricts it, so check your permissions if the link fails.
Downloading with the GitHub CLI
The GitHub CLI is useful when you want to script a download or avoid the browser. Install it, then sign in once with gh auth login. Run the commands from a clone of the repository, or add --repo OWNER/REPO to target another one.
Every run has a numeric ID. You can find it with gh run list, and it also appears at the end of a run's URL.
# Download the artifact named dist from a specific run
gh run download 1234567890 --name dist --dir ./dist
# Or list recent runs of a workflow first
gh run list --workflow build.yml --limit 5gh run list prints recent runs with their status and ID. Copy the ID from that output into gh run download. The options in the first command do the following:
| Option | Meaning |
|---|---|
| `1234567890` | The run ID. |
| `--name dist` | Download only the artifact called `dist`. You can repeat the option for several artifacts. |
| `--dir ./dist` | Write the files into this directory. |
What the CLI does with the files
gh run download extracts the ZIP for you. When you ask for one artifact by name with --dir, the files go directly into that directory. If you download several artifacts, or all of them, gh creates one subdirectory per artifact name. This is the same layout difference you saw with actions/download-artifact, where a single name puts files in path and a pattern creates one directory per artifact unless you set merge-multiple.
If you leave out the run ID, gh run download shows an interactive list of recent runs that have artifacts, and then lets you pick artifacts. This is convenient at a terminal, but it does not work in a script, so pass the ID there.
If you leave out --name, gh downloads every artifact in the run. Use --pattern with a glob such as results-* to download a group, which matches the matrix naming from the earlier chapter.
Choosing between the two
The web UI gives you a ZIP you must extract yourself. The CLI extracts for you and can fetch many artifacts in one command.
Common problems
- Authentication errors.
ghneeds a signed-in account with access to the repository. Rungh auth statusto check. - No artifacts found. The run may have no artifacts, or they may have expired. Check the retention period you set on upload.
- Files land in an unexpected directory. Remember that downloading several artifacts creates one subdirectory for each. Download by name if you want a flat layout.
- Wrong run. A failed run can still hold artifacts if the upload step used
if: always(). A successful run on another branch may hold a different build than the one you want, so check the run ID.
Exercise
You want to download every artifact whose name starts with results- from run 987654321 into ./reports, from a script that must not prompt. Which command do you use, and how will the files be arranged?
Show answer
Run gh run download 987654321 --pattern "results-*" --dir ./reports. Because the command matches several artifacts, gh creates one subdirectory per artifact name inside ./reports. Passing the run ID keeps the command from prompting.