I want to use curl
to download my private repo in GitLab. I know I can use the Gitlab API, but for some reason, It doesn't work.
Is this possible? When I try to do it this way, it always returns the login page.
I want to use curl
to download my private repo in GitLab. I know I can use the Gitlab API, but for some reason, It doesn't work.
Is this possible? When I try to do it this way, it always returns the login page.
This is possible, just follow these steps:
First, you have to create a "Personal Access Token":
Check "api Access the authenticated user's API"
Click "Create personal access token"
Make sure you save the token somewhere safe, you won't be able to view it again.
Now that you have your "Personal Access Token", you need to get your project id to use the API:
Get your project's id from the json.
Now you can call:
wget -O your_project.tar.gz https://gitlab.com/api/v3/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXX
And that'll download your project as a .tar.gz
file.
You can use the private token that is yours (found in "profile settings") to access any resource. Just browse to the repository file you want to download, copy the "raw" file link and append ?private_token=...
Example:
curl https://git.local/user1/myrepo/raw/master/myfile.txt?private_token=ahgiretherghaeoi
You can, but you need to authenticate yourself (as in "Gitlab API: How to generate the private token")
curl http://gitlab.server/api/v3/session --data 'login=myUser&password=myPass'
Then with the private token:
curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" "http://example.com/api/v3/projects"
Or, in your case, get the repository files:
GET /projects/:id/repository/files
Or, download directly one file.
If you need to do this in a CI run and your private repo is on the same server, you should be able to use git submodules to clone other repos at the same time. Using the ${CI_JOB_TOKEN}
is another option since GitLab 8.12.