Question

I'm using gitlab. When I go into the interface, on each branch I can download the source code as a zip, tar or whatsoever.

I am making rpm spec files for which I would need the possibility to download the tar ball using command line. since I added my rsa key i can do git clone without problems:

git clone http://gitlab/group/project.git
Cloning into 'project'...
remote: Counting objects: 1885, done.
remote: Compressing objects: 100% (826/826), done.
remote: Total 1885 (delta 1194), reused 1496 (delta 954)
Receiving objects: 100% (1885/1885), 1.30 MiB | 0 bytes/s, done.
Resolving deltas: 100% (1194/1194), done.
Checking connectivity... done

However doing

wget http://gitlab/group/project/repository/archive.zip

gets me these errors:

Resolving gitlab (gitlab)... 10.1.253.75
Connecting to gitlab (gitlab)|10.1.253.75|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authorization failed.
Was it helpful?

Solution

Since GitLab 6.2 and issue 5253, it should be:

GET /projects/:id/repository/archive

But that seems for internal use only, since you cannot know the id of a project as a user (only its name).

Don't forget, as shown in ability.rb, that downloading an archive is linked to a permission. Make sure you have that "download_code" permission set for your project.

Here, it must be a permission issue, because, for instance:

wget http://demo.gitlab.com/gitlab/gitlab-recipes/repository/archive.zip

That works just fine, and get the content of that project without any issue.


However, as the OP Chris Maes comments and mentions in issue 6645, as as illustrated by app/models/ability.rb:

 if project && project.public?

... that "dowload_code" feature is only for public projects.

OTHER TIPS

For me the private_token and the sha or ref parameters does not worked together. So, I changed the way, and I tell my private token via a header parameter to the Gitlab API, like this:

wget http://{{your_host}}/api/v3/projects/{{project_id}}/repository/archive?sha={{commit_sha}} --header='PRIVATE-TOKEN: {{private_token}}'

try this

curl http://$yourhost:$port/$yourgroup/$yourrepo/repository/archive.zip\?ref\=$yourbranch\&\private_token\=$yourtoken -o newpackage.zip

With the newer version of gitlab, you can use

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/archive?sha=<commit_sha>"

You can also pass different archive format, e.g tar.bz2

curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.com/api/v4/projects/<project_id>/repository/archive.tar.bz2?sha=<commit_sha>"

I didn't want to have to get the project ID first, but rather use group|org and repository name similar to the Github HTTP API. This is what works for me on 11.9.0-ce.0

Private/Internal Project

curl "https://gitlab.yourdomain.com/api/v4/projects/engineering%2Faccount-service/repository/archive?sha=some-branch-name" \
  -H "Private-Token: $GITLAB_TOKEN" \
  -o /tmp/account-service-branch-name.tar.gz

Public Project

curl "https://gitlab.yourdomain.com/engineering/account-service/repository/archive.tar.gz?ref=some-branch-name" \
  -o /tmp/account-service-branch-name.tar.gz

In this example

  • "group" is engineering
  • "repository" is account-service

Don't forget the %2F between group and repo

Hope it helps anyone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top