continuous integration - Where to obtain the token to register a GitLab runner? - DevOps Stack Exchange
Question about ways to register GitLab Runner using Runner Authentication tokens.
Obtaining a "gitlab runner token" - Stack Overflow
Generate Runner's authentication token using gitlab-rails
Videos
The projects API endpoint response contains the runners_token key. You can use this to automatically fetch the runner tokens for any project.
You can then use that in a few ways. One way would be to have your runner registration script fetch the runner token itself such as with this example:
curl --fail --silent --header "Private-Token: ${GITLAB_API_TOKEN}" "https://$GITLAB_URL/api/v4/projects/${PROJECT}"
Or you could use the Gitlab Terraform provider's gitlab_project data source to fetch this from whatever is running Terraform and then inject it into the thing that runs the registration script such as a templated file:
data "gitlab_project" "example" {
id = 30
}
locals {
runner_config = {
runner_token = data.gitlab_project.example.runners_token
}
}
output "example" {
value = templatefile("${path.module}/register-runners.sh.tpl", local.runner_config)
}
Yes, you can.
The command has to be run on the server hosting your Gitlab instance. The line below will output the current shared runner token.
sudo gitlab-rails runner -e production "puts Gitlab::CurrentSettings.current_application_settings.runners_registration_token"
As others have mentioned, there is not API endpoint that currently allows this (there has been discussion over this for quite some time here. However, I find this solution satisfactory for my needs.
Hello. Since gitlab-runner registration using Runner Registration tokens is getting deprecated and I saw that registration using Runner Authentication tokens is the new way, I have got a question to ask. Do I understand correctly that there are only two ways to retrieve the Runner Authentication token (according to documentation: https://docs.gitlab.com/runner/register/ ) ?
-
Either when clicking create new runner using GitLab GUI and then copying the token when it is shown for limited time;
-
Or if I do not manage to copy it I can still find it in the `
config.toml` file.
Just wanted to make sure there are no other way to retrieve this token.
