Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download artifacts using an URL in a gitlab job?

Tags:

gitlab

In the gitlab documentation some URL's are described for the purpose of downloading artifacts from pipelines HERE. They seem to have forgotten to describe HOW to download artifacts given these URLs.

Can it be done in a simple way? Or do I have to install e.g. wget, create a token, define a token, use a token?

If someone could give an example that would be great.

like image 519
Alex Avatar asked Oct 15 '25 20:10

Alex


1 Answers

The documentation referenced in the question is supposed to be an REST API call, using the Job Artifact API:

GET /projects/:id/jobs/artifacts/:ref_name/download?job=name

To use this in a script definition inside .gitlab-ci.yml, you can use either:

  • The JOB-TOKEN header with the GitLab-provided CI_JOB_TOKEN variable.
    For example, the following job downloads the artifacts of the test job of the main branch.
    The command is wrapped in single quotes because it contains a colon (:):
artifact_download:
stage: test
script:
  - 'curl --location --output artifacts.zip --header "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/main/download?job=test"'
  • Or the job_token attribute with the GitLab-provided CI_JOB_TOKEN variable.
    For example, the following job downloads the artifacts of the test job of the main branch:
artifact_download:
 stage: test
 script:
   - 'curl --location --output artifacts.zip >"https://gitlab.example.com/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/main/download?job=test&job_token=$CI_JOB_TOKEN"'

But the artifact: directive is meant to store data in the job workspace, for a new iteration of the job to get back, in the same folder.

No "download" involved, as illustrated in the article "GitLab CI: Cache and Artifacts explained by example" by Anton Yakutovich.
As such, no curl/wget/TOKEN should be needed to access an artifact stored by a previous job execution.

like image 84
VonC Avatar answered Oct 18 '25 21:10

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!