Retrieving runner tokens from console

I am scripting a setup of gitlab along with some nice initial repositories containing pipelines.
I would like to make this environment completely runnable from the start by registering runners at install/configure time.

I know how to find my runner token for a project using the console. But as the API is not documented (AFAIK) I have not been able to figure out how to find the shared runner token. It is important to me to use a single shared runner as I do have jobs that are written sloppy enough that they can interfere.

Is there anyone who knows how to do this in a scripted way?

1 Like

I decided to dig in the source code to find an answer to this question and came up with the following:

registration_token=gitlab-rails runner -e production " \
puts Gitlab::CurrentSettings.current_application_settings.runners_registration_token"

This works fine to retrieve the common token which I will also use a runner on the same server for.

However for any project I noticed that you can change the project specific token like this:

gitlab-rails runner -e production " \
  proj=Project.find_by(name:'repository-name'); \
  proj.shared_runners_enabled=false; \
  proj.runners_token="my-defined-token"; \
  proj.save!"

The latter piece is nice if you need to know beforehand what the tokens shall be. Of course you need to think about what this means for your security as well.

I hope someone has any use of this information.

5 Likes