Reputation: 185
Im trying to create a bash script to download a private release from GitLab using curl but it keeps getting redirected to the signin page.
How can I do this?
I have tried the following with no luck:
curl --header "PRIVATE-TOKEN: XXXXXXXXX" "https://gitlab.com/mrhid6/test/-/archive/v0.0.5/test-v0.0.5.zip"
Upvotes: 7
Views: 12364
Reputation: 1335
According to the bug (now at https://gitlab.com/gitlab-org/gitlab/-/issues/28978) and to my tests, this is finally possible using the Private-Token header
curl -SsfLO \
-H 'Private-Token: <PERSONAL_ACCESS_TOKEN>' \
https://gitlab.com/<USER>/<REPO>/-/archive/<RELEASE_NAME>/<FILE_NAME>
If using Generic Packages for your release assets (I recommend this), then use
curl -SsfLO \
-H 'Private-Token: <PERSONAL_ACCESS_TOKEN>' \
https://gitlab.com/api/v4/projects/<URL_ENCODED_USER_SLASH_REPOSITORY_NAME>/packages/generic/release/<RELEASE_NAME>/<FILE_NAME>
Upvotes: 0
Reputation: 923
As Win32Sector says, it is a bug, but the issue is open for quite a long time and it is constantly pushed to the next milestone...
As a workaround, you can use Package Registry as a data store and then reference the package files from the Releases page, so that user does not recognize anything:
Enable Package registry - tick Packages in Project -> Settings -> General -> Visibility, project features, permissions.
Upload a package via Package API:
curl --header "PRIVATE-TOKEN: ####" --upload-file /local/file/asset-file.txt https://<your.gitlab.instance>/api/v4/projects/<PROJECT>/packages/generic/<PACKAGE_NAME>/<VERSION>/asset-file.txt
curl --request POST --header "PRIVATE-TOKEN: ####" --data name="My asset name" --data link_type="package" --data url="https://<your.gitlab.instance>/api/v4/projects/<PROJECT>/packages/generic/<PACKAGE-NAME>/<VERSION>/asset-file.txt" "https://<your.gitlab.instance>/projects/<PROJECT>/releases/<VERSION>/assets/links"
curl --header "PRIVATE-TOKEN: ####" "https://<your.gitlab.instance>/api/v4/projects/<PROJECT>/packages/generic/<PACKAGE-NAME>/<VERSION>/asset-file.txt"
Upvotes: 6
Reputation: 73
Gitlab said it is bug =(
https://gitlab.com/gitlab-org/gitlab-ce/issues/62307
I want to download assets too.
Upvotes: 3
Reputation: 2541
You cannot use the Private token to access the repository zip file like that.
Check https://docs.gitlab.com/ee/api/repositories.html#get-file-archive, you should be using this:
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.com/api/v4/projects/mrhid6%2Ftest/repository/archive.zip
Upvotes: -2