curlgitlabgitlab-cigitlab-api

Download artifacts from a Gitlab job


I'm trying to download artifacts from a Gitlab build (hosted on gitlab.com) according to the documentation

So I run the following command :

curl --location --output artifacts.zip --header "PRIVATE-TOKEN: <my-token>" "https://gitlab.com/<group-name>/api/v4/projects/<project-name>/jobs/artifacts/develop/download?job=build"

All I have from that is a HTML page entitled "Just a moment..." but no artifact archive.


Solution

  • You'll want to ensure that your path is correct.

    Current, you have:

    https://gitlab.com/<group-name>/api/v4/projects/<project-name>/jobs/artifacts/develop/download?job=build
    

    instead, it should be:

    https://gitlab.com/api/v4/projects/<group-name>%2F<project-name>/jobs/artifacts/<ref_name>/download?job=<name>
    

    So let's assume your group/project path is: some-group/my-project then based on what you've provided, it would be:

    https://gitlab.com/api/v4/projects/some-group%2Fmy-project/jobs/artifacts/develop/download?job=build
    

    Remember that if you use a namespace path instead of the project ID, it needs to be URL encoded. (Personally, I always use project ID for this reason.)

    When looking at the REST API documentation, the endpoint is always what comes after https://gitlabinstance.example.com/api/v4.