I want to clone gitlab repository without prompt for my automation script, by using my private token from my gitlab account.
Can someone provide me a sample?
<As of 8.12
, cloning using HTTPS
+ runner token is not supported anymore, as mentioned here:
In 8.12 we improved build permissions. Being able to clone project using runners token it is no supported from now on (it was actually working by coincidence and was never a fully fledged feature, so we changed that in 8.12). You should use build token instead.
This is widely documented here - https://docs.gitlab.com/ce/user/project/new_ci_build_permissions_model.html.
Use the token instead of the password (the token needs to have "api" scope for clone to be allowed):
git clone https://username:token@gitlab.com/user/repo.git
Tested against 11.0.0-ee.
Inside a GitLab CI pipeline the CI_JOB_TOKEN
environment variable works for me:
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/...
Source: Gitlab Docs
BTW, setting this variable in .gitlab-ci.yml
helps to debug errors.
variables:
CI_DEBUG_TRACE: "true"
One possible way is using a deploy token (https://docs.gitlab.com/ee/user/project/deploy_tokens). After creating the token, use:
git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
as mentioned in the link above.
If you already has a repository and just changed the way you do authentication to MFA, u can change your remote origin
HTTP URI to use your new api token as follows:
git remote set-url origin https://oauth2:TOKEN@ANY_GIT_PROVIDER_DOMAIN/YOUR_PROJECT/YOUR_REPO.git
And you wont need to re-clone the repository at all.
The gitlab has a lot of tokens:
I tested only the Personal Access Token using GitLab Community Edition 10.1.2, the example:
git clone https://gitlab-ci-token:${Personal Access Tokens}@gitlab.com/username/myrepo.git
git clone https://oauth2:${Personal Access Tokens}@gitlab.com/username/myrepo.git
or using username and password:
git clone https://${username}:${password}@gitlab.com/username/myrepo.git
or by input your password:
git clone https://${username}@gitlab.com/username/myrepo.git
But the private token seems can not work.