Allow optional flag to download latest job even if it is not present in latest pipeline
Release notes
An optional flag can now be provided when downloading the artifacts archive via API for a job where the job has not run on the latest pipeline. The previous behaviour was to only consider the latest pipeline and return a 404
response if the job did not run on this pipeline.
Problem to solve
A Large SaaS Customer contacted Support in this ticket (links are internal use only) to discuss the wording and design of the current documentation regarding artifact downloads for jobs. It was confirmed through further testing with the customer that in some situations, users may want to grab the latest archive of a job even if it did not run on the latest pipeline. Here's an example:
Public Project: https://gitlab.com/benjaminking_ultimate_group/zd473578/-/pipelines
In this project, there are two pipelines:
- The first ran five jobs over two stages, including jobs
four
andfive
that contain artifacts we want to download at a later time. - The second and most-recent pipeline only ran one stage, and did not run jobs
four
andfive
.
If we try and use this API endpoint, it will fail to download:
### Downloading artifact from job three
➜ ~ curl -v --output artifacts.zip --location --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/52565035/jobs/artifacts/main/download?job=three"
<omitted for brevity>
< HTTP/2 200
### Downloading artifact from job four. Not present on latest pipeline
➜ ~ curl -v --output artifacts.zip --location --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/52565035/jobs/artifacts/main/download?job=four"
<omitted for brevity>
< HTTP/2 404
This does appear to work as designed, but the documentation could be seen as confusing. This text from the docs notes that:
Download the artifacts zipped archive from the latest successful pipeline for the given reference name and job,
It is reasonable that some users might not understand that by latest successful pipeline, we only refer to the latest pipeline, and don't take into consideration if the job was run in an earlier pipeline, as this endpoint is specifically for specifying the job name.
This feature proposal has some overlap with Artifacts - Allow needs:project
to download from a successful job
which wants an optional flag for needs:project
within a CI/CD job.
Ultimately, some users may want to have the option to download the 'latest artifact' for a job regardless of whether this was present in the latest pipeline.
Proposal
To reduce changing current functionality too much, we should add an optional flag which can be provided in the API call (or needs:project
in CI/CD), that indicates to grab the latest job artifact regardless of whether it ran on the latest pipeline. For example, something like always_get_latest_job=true
could indicate to always get the artifact, bypassing the checks against the latest pipeline.