Generate Runner's authentication token using gitlab-rails

There is a way to generate a Runner’s registration token using gitlab-rails:

gitlab-rails runner "token = Gitlab::CurrentSettings.current_application_settings.runners_registration_token; puts token"

Similarly I’m looking for a way to generate Runner’s authentication token as well? I cannot find the command to do it. Does it even exist? or how else can i do it via CLI ?

The authentication tokens differ by job (AFAIR), and I think the token for any particular job is available as an environment variable in that job, which I guess is pretty much where you might need it.

What are you trying to do?

I’m looking for non-interactive (programatically) way of generating the authentication token and then create the runner using gitlab-runner register command…

For example:

RUNNER_TOKEN = gitlab-rails runner ????

gitlab-runner register \
    --non-interactive \
    --executor "shell" \
    --url "https://gitlab.com/" \
    --token "$RUNNER_TOKEN"

I’ve checked the documentation and I can see that they actually use the term “authentication token” for the token used solely for registering a new token. I had forgotten that (I probably knew when I worked on automating runner registration in our setup and looked at that page regularly). That’s not what I was talking about and I’m sorry for causing some confusion.

The rails commands (gitlab-rails runner ...) are only usable on the GitLab servers, and the first requirement for registering a runner listed on:

says that the runner should be on a seperate server. But you can use the API to get an authentication token. I think there was a better page on how to do it than what I can find now, but here are the commands (slightly edited to hide secrets) I got working:

# curl -k -H 'PRIVATE-TOKEN: <secret>' -X POST 'http://10.0.3.17:/api/v4/user/runners?runner_type=instance_type&description=test&paused=True&tag_list=test'
{"id":1,"token":"glrt-<also secret>","token_expires_at":null}

# gitlab-runner register --non-interactive --url http://10.0.3.17 --token "glrt-<also secret>" --executor shell

(10.0.3.17 was the ip of the GitLab instance I worked against)