Retrieve the list of all projects which I am member and with 100 results by page :
curl -H "PRIVATE-TOKEN: MY_GITLAB_TOKEN" "http://foo-gitlab.com/api/v4/projects?per_page=100&simple=true&membership=true"
Download a file from a repository:
curl -v -o README.md -H 'PRIVATE-TOKEN: MY_GITLAB_TOKEN' "http://foo-gitlab.com/api/v4/projects/1234/repository/files/foo%2Fbar%2FREADME.md/raw?ref=master"
where :
– 1234
is the project id
– master
is the git branch
– foo/bar/README.md
is the path of the requested file with URL encoded full path (especially %2F for / char)
Download an artifact from a finished job:
curl -l -H "PRIVATE-TOKEN: MY_GITLAB_TOKEN" "https://foo-gitlab.com/api/v4/projects/1234/jobs/14927938/artifacts" -o artifact_angular.zip
where :
– 1234
is the project id
– 14927938
is the job id
Retrieve commits (no details about files/changes):
Ex :
a) Retrieve commits from a project (1234 id project) and a specific branch or tag (develop)
curl -k -v -l -H 'PRIVATE-TOKEN: MY_GITLAB_TOKEN' "https://gitlab.com/api/v4/projects/1234/repository/commits?ref_name=develop"
where :
– 1234
is the project id
– develop
is the git branch
b) Retrieve commits between two dates (01/06/21 until 24/12-21) from a project (1234 id project) and a specific branch or tag (develop)
curl -k -v -l -H 'PRIVATE-TOKEN: MY_GITLAB_TOKEN' "https://gitlab.com/api/v4/projects/1234/repository/commits?ref_name=develop&since=2021-06-01T00:00:00Z&until=2021-12-24T00:00:00Z"
Compare two commits (details about files/changes):
Ex :
a) Retrieve commits from a project (1234 id project) and a specific branch or tag (develop)
curl -k -v -l -H 'PRIVATE-TOKEN: MY_GITLAB_TOKEN' "https://gitlab.com/api/v4/projects/1234/repository/compare?from=777commitId&to=888commitId"
where :
– 1234
is the project id
– develop
is the git branch
The api returns a json response with three attributes:
– commit : an object with the last commit info (to param in the request)
– commits : an array with info of each commit in the requested interval
– diffs: an array with final diffs (so only between the interval, not for each commit) : modified file and the diff
Git operations
Clone a gitlab repo with a token :
git clone https://oauth2:myToken@gitlab.com/foo/bar/myrepo.git
If we want to specify the token during a push operation we have to specify it as a password and we have to provide the username too.