9

It's unclear from the API how to get the token that can be used to clone http repositories.

From the documentation here:

http://doc.gitlab.com/ee/ci/api/README.html

It should be possible to GET this url:

http://gitlab.com/ci/api/v1/projects?private_token=QVy1PB7sTxfy4pqfZM1U&url=http://demo.gitlab.com/

I'm not sure where the url parameter is taken from but even with just my private token, it receive a 404 error page.

I tried with the ci subdomain but it simply redirect me to gitlab.com.

That said, I'll explain a bit more the reason why I need that. I have a server that could have multiple projects. Each projects will contain a list of repositories private/public each project has to be cloned/pulled and whatever regularly. Unlike github, gitlab doesn't provide a oauth2 token that is sitewide and instead provide a CI-token for each project. I could make sure that the user enter the token for each project but that is way more complicated than entering the private token.

On the other hand, I could generate SSH keys for each users and add the public key to their account and this way it would be possible to fetch/clone with ssh instead of http. But that is a bit more work on my end than just fetching a token and cloning with a basic auth url

git clone https://gitlab-ci-token:[email protected]/project.git
1
  • Note that the gitlab-ci-token authentication is deprecated and not available for new projects. You must use trigger authentication system as described here docs.gitlab.com/ee/user/project/…. Commented Jun 21, 2019 at 5:02

5 Answers 5

8

You can find the token by doing the following from gitlab.com

  1. Click on the project you are working on from the starting screen
  2. Click "Settings" on the left hand navigation
  3. Scroll down to the bottom and click "CI / CD" which is nested in Settings
  4. Under the "Runners" section click expand
  5. Token is hidden here.

Took me 10 minutes to find this... not documented anywhere.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the runner token, not the API token. There are several different tokens in Gitlab (at least runner, CI/job, and personal).
Solved my issue when gitlab-runner wizard prompted to "enter the gitlab-ci token for this runner"
5

According to new Gitlab CI Build Permissions Model, HTTPS is now a requirement to clone all the sources. So that rules out the SSH option.

Now to clone any private repo you can just do:

git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/<group_name>/<repo>.git

Also, you DONT need to specify the value for CI_JOB_TOKEN. It is taken automatically. So, just fill in the <group_name> and <repo>.

Also, remember that gitlab.com can be replaced by gitlab.xyz.cloud (your private gitlab enterprise) and this will still work.

Needless to say that you would never actually require the value of CI_JOB_TOKEN

Comments

3

The url to retrieve your token is located under the following path /profile/account.

Or you can just navigate to Profile Settings -> Account

Also make sure you are using the right version of the api. At the time of this response is currently on v3 /api/v3/projects?private_token={my_private_token}

5 Comments

What you're talking about is the gitlab api. My question is about the gitlab-ci api. CI stands for Continuous Integration.
That is exactly what I'm talking about. I saw the question, solved it on my Gitlab-CI and then answered it. But still, that is how you get the CI private token.
No, the API that you linked api/v3/projects is a gitlab api not a CI API. The CI API would be under the /ci/api/:version prefix. Apparently, the API that was present in the documentation at the time I wrote this question disappeared and moved to the main "gitlab" api. I needed it for webhooks. I think it changed when gitlab-ci and gitlab pretty much merged and became one product.
Correct, but to answer your question. The token is located under Profile Settings -> Account
Looks like it moved to Access Tokens in the User Settings? gitlab.com/profile/personal_access_tokens There you can create a personal access token and grant API access for instance.
2

gitlab-ci-token**strong text**

gitlab-ci-token can be found at [Go to left side panel -> settings -> ci/cd->runners]

Comments

1

I would say to check the type of token you want.

  1. Private token? Navigate to Profile Settings -> account.

  2. A token can be generated if you want to trigger a new CI/CD pipeline and this can be done by navigating to Project Settings-> CI/CD pipelines -> Create a token

Also, It is important that you have the right privileges to Git.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.