24

I'm trying to unregister gitlab-runner on EC2 instance (Ubuntu machine) with the following command:

sudo gitlab-runner --debug unregister --token [RUNNER-TOKEN] --url [RUNNER-URL]

and I'm getting following error:

Runtime platform                                    arch=amd64 os=linux pid=2374 revision=6fbc7474 version=13.1.1
Checking runtime mode                               GOOS=linux uid=0
Running in system-mode.

Dialing: tcp gitlab.com:443 ...
ERROR: Unregistering runner from GitLab forbidden   runner=xv2Ng6Tc
FATAL: Failed to unregister runner

5 Answers 5

35

Make sure that you're using the entire SHA, not the partial one listed on the Gitlab CI runners list.

This can be found by running sudo gitlab-runner list on the machine with the runner installed.

If you've already removed the runner in the gitlab runners page, it will still be present on the gitlab-runner machine (check with the command sudo gitlab-runner list).

You can then unregister it from the config.toml using the command:

gitlab-runner verify --delete

Or manually, by running:

  • sudo gitlab-runner stop
  • sudo vi /etc/gitlab-runner/config.toml # update the runners section
  • sudo gitlab-runner start
2
  • 1
    Btw, this should be the answer!
    – ZoliRkty
    Jun 3, 2021 at 21:42
  • 1
    gitlab-runner verify --delete will not work if the gitlab url does not longer exists, but manually remove works like a charm. May 5, 2022 at 9:47
21

For MacOS and Ubuntu

If you have already removed it from the Runners section in your project settings then you are no longer be able to unregister with command. Then what you can do is to delete them from your host as below:

gitlab-runner verify --delete 

This will remove all the unregistered/removed runners from your host machine and will update config.toml file.


If you haven't removed it from Runners section in your project settings(Settings -> CI/CD -> Runners), then you can unregister it from your host like below:

gitlab-runner unregister runner_id/name

or unregister all runners,

gitlab-runner unregister --all-runners

Hope this will help to somebody. cheers !!!

1
  • I had configured a runner for a project. Then decided I wanted a shared runner, and removed it from the project and set up a runner with the same name. When I wanted to reconfigure the latter runner, I couldn't unregister it by name (-n) until I used the gitlab-runner verify --delete command to clear out the original.
    – Auspex
    Nov 16, 2022 at 11:29
4

I experienced the same issue when I tried to remove a runner that was removed directly from Gitlab settings of the project. It seems that "Remove runner"'s button removes the runner from Gitlab but not from your gitlab-runner, which is absolutely fine since I don't want Gitlab to mess up to my on-premise gitlab-runner.

Cursed button here

In order to fix that, I stopped the gitlab-runner service, removed the runner directly from the config file (it is usually located in /etc/gitlab-runner/config.toml) and started the service again.

I hope I could help you ;)

1
  • gitlab-runner verify --delete would have done that without editing a config file
    – Auspex
    Nov 16, 2022 at 11:31
1

If someone is still struggling with this like me, then here is something from docs: https://docs.gitlab.com/runner/commands/#gitlab-runner-unregister

gitlab-runner unregister --url http://gitlab.example.com/ --token <full_token_from_etc/gitlab-runner/config.toml>

0

I ran into the same issue. I had to enter the right token in the config.toml file and boom, it worked: See this guide for more information: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4919. This solution is specifically for Windows, but can be applicable to Ubuntu as well.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.