I have a pipeline that has multiple jobs each producing two types of artifacts - headers inside include
directory and library binaries inside lib
directory. I download these artifacts during the configuration stage of a CMake project using FetchContent
.
Since all artifacts from a pipeline end up in the same location unless instructed otherwise, I am thinking of adding a cumulative CI job that needs
all other jobs and allows me to download all artifacts at once if everything is successful. So at the time the pipeline starts executing that cumulative job, all other CI jobs (if successfully completed) it depends on would have already stored their artifacts in the specific locations ready to be archived, downloaded unpacked and used.
According to GitLab Job Artifacts API documentation there are two ways of GET
ting the artifacts:
using the exact job ID
https://gitlab.example.com/api/v4/projects/<PROJECT-ID>/jobs/<JOB-ID>/artifacts
using the tag/branch reference plus the job's name
https://gitlab.example.com/api/v4/projects/<PROJECT-ID>/jobs/artifacts/<TAG|BRANCH>/download?job=<JOB-NAME>
The first possibility is not really useful in my case since I first need to retrieve the pipeline ID, then all the jobs and finally filter out the job that I am looking for. While the GitLab API can be used (and I have done this many times) in a CI job (incl. sorting and filtering as URL parameters!), I would like to avoid adding too much clutter if there is a better way.
The second option seems to deliver exactly what I am looking for. Both the name of the project and the CI job can be viewed as constants, meaning that this should in fact deliver the latest version of the artifacts in my cumulative job.
The problem is that I get
{
"message": "404 Not found"
}
I assume that the group access token I was using for the first option (it works without a problem) should be applicable for the second one so I really don't understand what the problem is. Even if PRIVATE-TOKEN
or similar was missing, I am expecting to get Permission denied
and not Not found
.
The name (both in the WebUI as well as in the JSON returned by the GitLab API) is correct. The repository currently has only main
branch, so that's not it either.
[
{
"id": 7024131,
"status": "success",
"stage": "build-debug",
"name": "build-debug-all", <------- <JOB-NAME>
"ref": "main", <------- <TAG|BRANCH>
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2024-08-09T06:31:55.117Z",
"started_at": "2024-08-09T06:33:13.498Z",
"finished_at": "2024-08-09T06:34:06.020Z",
"erased_at": null,
"duration": 52.521617,
"queued_duration": 2.942895,
"user": {
...
}
...
},
...
]
I also tried this on multiple of my other jobs (the ones that this cumulative one needs
) and the result is the same.
There are number of issues that should be checked:
Download the artifacts zipped archive from the latest successful pipeline for the given reference name and job, provided the job finished successfully. Therefore, if you have a manual job that has blocked the pipeline and the pipeline is in blocked (or failed) state, it will not download it.
reference (branch or tag) is correct - check if the tag
or branch
exist and the pipeline is executed for it
token permission - make sure you have personal, job and/or group access token (depending on where the URL is called from) that works for the given project