Reputation: 67057
https://stackoverflow.com/a/52074198/520162 shows a way to push with an access token. But how do I push with a project access token? What is access-token-name
in that case?
Upvotes: 2
Views: 13491
Reputation: 251
The gitlab documentation is relatively clear about this. You can use any non-blank value as a username and the project access token as the password. You can create a remote or push to the URL directly:
git push https://bla:[email protected]/my-group/my-subgroup/my-project.git
What isn't documented on that page, is that the role that you assign to the token actually matters. The token will have the privileges that were assigned to those roles, as described in this documentation page. That means that your token won't be able to push if you have granted it the role of "Guest" and your repository is private.
Upvotes: 2
Reputation: 67057
The answer given by @sytech works but requires you to track token generation count in order to construct a valid username.
With a little experimenting, I found out that you can also use gitlab-ci-token
:
git remote set-url origin \
"https://gitlab-ci-token:${YOURTOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
Upvotes: 4
Reputation: 40891
Project access tokens work exactly the same as personal access tokens. The access token belongs to the project bot user that is created when you create the token.
So, in this case, you should be using the username, which is project_{project_id}_bot
for the first access token created. For subsequent tokens, the username is project_{project_id}_bot{bot_count}
So you would do something like this:
git remote add origin \
"https://project_1234_bot:[email protected]/path/to/project.git"
Upvotes: 5