How to git clone private repositories without SSH using the runner or private token?

Trying to clone a private gitlab repository without using ssh with the runners token as recommended here.

Unfortunately running (replaced with real values) git clone https://gitlab-ci-token:<private token>@git.example.com/myuser/myrepo.git fails with:

remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab-ci-token:<private token>@git.example.com/myuser/myrepo.git/'

I’ve read that the CI feature has new build permissions.

There doesn’t seem to be an alternative command to do this, or is there? How can I clone a private gitlab repository using a token?

1 Like

Using CI_JOB_TOKEN as explained in this section in the doc you reference to, I was able to clone a private repo. This variable is already defined by Gitlab CI for you so you just use it as is, as in the example (below, what you need to fill in is what begins with my):

git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/myuser/mydependentrepo
1 Like