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?
<Customising the URL is not needed. Just use a git configuration for gitlab tokens such as
git config --global gitlab.accesstoken {TOKEN_VALUE}
extended description here
I know this is old but this is how you do it:
git clone https://oauth2:ACCESS_TOKEN@somegitlab.com/vendor/package.git
These days (Oct 2020) you can use just the following
git clone $CI_REPOSITORY_URL
Which will expand to something like:
git clone https://gitlab-ci-token:[MASKED]@gitlab.com/gitlab-examples/ci-debug-trace.git
Where the "token" password is ephemeral token, it should be revoked after a build is complete.
To make my future me happy: RTFM - don't use the gitlab-ci-token at all, but the .netrc
file.
There are a couple of important points:
echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
$CI_JOB_TOKEN
within the file!https://gitlab.com/whatever/foobar.com
- not ssh://git@foobar
, not git+ssh://
, not git+https://
. You also don't need any CI-TOKEN stuff in the URL.git clone [url from step 4]
Background: I got
fatal: could not read Username for 'https://gitlab.mycompany.com': No such device or address
when I tried to make Ansible + Gitlab + Docker work as I imagine it. Now it works.
You can use the runners token for CI/CD Pipelines of your GitLab repo.
git clone https://gitlab-ci-token:<runners token>@git.example.com/myuser/myrepo.git
Where <runners token>
can be obtained from:
git.example.com/myuser/myrepo/pipelines/settings
or by clicking on the Settings icon -> CI/CD Pipeline
and look for Runners Token on the page
Screenshot of the runners token location:
I went SSH using the per project deploy keys setting (read only)