How do I register/reregister a Gitlab Runner using a pre-made config.toml?

int*_*ect 4 gitlab gitlab-ci gitlab-ci-runner

I recently wanted to move a Gitlab runner that I had set up for my self-hosted Gitlab instance from being a project runner (i.e. running jobs only for a project) to being a group runner (so it could also run jobs for other projects in the same group). I wanted to retain the /etc/gitlab-runner/config.toml settings that I had painstakingly hand-written.

Luckily I backed up config.toml, because sudo gitlab-runner unregister -t ... -u ... deleted the whole configuration from config.toml.

In order to get the same config registered under the group instead of the project, I had to:

  1. Register the runner in a paused state with a dummy configuration, with the group's registration token:
sudo gitlab-runner register \
  --non-interactive \
  --url <URL HERE>
  --registration-token <TOKEN HERE> \
  --executor docker \
  --docker-image docker:dind \
  --paused
Run Code Online (Sandbox Code Playgroud)
  1. Go into the new config.toml that this created and copy the runner's individual runner token.

  2. Overwrite config.toml with my desired configuration.

  3. Edit the config.toml and plug in the new individual runner token.

  4. Start the Gitlab runner sercice (sudo systemctl start gitlab-runner).

  5. Unpause the runner in the Gitlab web UI.

Even after doing all this, the Gitlab instance still sees the runner under the name it registered with in the dummy config, rather than the name in the config.toml.

Trying the --config option to gitlab-runner register didn't work at all; I think that just tells it where to save the config. It still prompted me for new settings to use instead of reading from the config.toml I pointed it at.

The Gitlab documentation on runner registration is all written around one shot gitlab-runner register commands with loads of options on them that essentially specify the whole config on the command line. I really don't want to translate my config.toml manually into a command line that turns around and rebuilds it (minus any comments, of course).

I can't believe that this is really the right workflow to re-register a runner with a new project/group/Gitlab instance, or to create a copy of a runner from a saved config. What am I missing here? How can I create a new Gitlab runner from an existing config.toml file?

MrB*_*rta 7

根据我在 GitLab 文档中可以找到的内容以及他们遇到的一些未解决的问题,没有一种简单的方法可以做你想做的事。

这是一个描述类似于您想要的内容的问题:

https://gitlab.com/gitlab-org/gitlab-runner/issues/3540

我认为 GitLab 的目标是如何注册跑步者:

https://gitlab.com/gitlab-org/gitlab-ce/issues/40693

我相信您不能从 .toml 文件中更改的唯一内容是运行程序的名称,也可能不是标签。然后名称仅在您注册跑步者时创建。我在某处读到一些可以更改共享跑步者标签的内容,但现在找不到了。

这是一种使注册过程更加自动化的解决方法:

https://gitlab.com/gitlab-org/gitlab-runner/issues/3553#note_108527430

他使用了这个 API:

curl --request POST "https://gitlab.com/api/v4/runners" --form "token=<registration-token>" --form "description=test-1-20150125-test" --form "tag_list=ruby,mysql,tag1,tag2"
Run Code Online (Sandbox Code Playgroud)

然后他得到了以下回复:

{"id":401513,"token":"<runner-token>"}
Run Code Online (Sandbox Code Playgroud)

然后,他可以将 runner-token 注入到他已经预制的 .toml 文件中。

对您来说,可以使用您的组的注册令牌,然后写入跑步者的描述/名称和标签。然后你可以重新使用你的 config.toml 并且只更改 runner-token,它应该可以工作。