12

Is it possible to run a pipeline on a specific runner? (not using tags)

Is it feasible to use environments, or even gitlab runner exec maybe?


Scenario:

Have an existing project with multiple runners already attached to it (specific project token used to register the runner) and has it's own associated tags (so can't change these either).

I'm adding a new runner, however need to test it first to ensure it works, but I need to force the pipeline to build on this machine, without changing any tags, or specific project of the runner.

Rekovni
  • 3,672
  • 3
  • 26
  • 46
  • Tags and restricted runners are the way Gitlab designed running jobs on specific runners. Why can't you use them? – Stefan van Gastel Nov 01 '17 at 17:59
  • @StefanvanGastel I've updated the question – Rekovni Nov 02 '17 at 10:30
  • I have another use case: We have a bunch of runners but only one of them shows a specific problematic behaviour (RNG seems to be broken). I would like to illustrate this to the IT department, but the demonstrator project is scheduled on the healthy runners only. So I can't demonstrate that something is broken without first getting the admins to change the config (adding tags) to be able to demonstrate this. – Bluehorn Jul 31 '19 at 09:22
  • any improvement after 3 years ? – Pavel Niedoba Dec 09 '20 at 16:28

3 Answers3

4

You have two mechanisms by which you can attempt to isolate a new runner for testing:

  1. use tags and private runner attachment (already called out)
  2. use the gitlab-runner exec verb directly on the runner
  3. canary the runner for a single build only

Option 1

use tags and private runner attachment (already called out).

To further expand on this... even in a draconian setup where you can't alter tags and whatnot -- you can always FORK the project.

In your new private fork, you can go to Settings >> CI/CD and override the .gitlab-ci.yml file in the Custom CI Configuration Path under the General Pipelines Settings. This allows you to git cp .gitlab-ci.yml .mycustomgitlab-ci.yml and then simply git add/git commit/git push and you're in business.

Opinion: If you cannot use the mechanisms in place to adjust the tags on the questionable runner and isolate a new forked project, this isn't a technical problem, it is a political problem.

Option 2

Gitlab-runner exec....

Assuming you're using a shell gitlab runner...

  1. SSH to the questionable gitlab runner box you're trying to test
  2. Clone the repo for the project in question to ... say ... /tmp/myrepo
  3. Execute Gitlab-Runner: /path/to/gitlab-runner exec shell {.gitlab-ci.yml target}

See https://docs.gitlab.com/runner/commands/#gitlab-runner-exec and a blog about it at https://substrakt.com/how-to-debug-gitlab-ci-builds-locally/

Option 3

Canary the gitlab-runner for a single build.

You can spin up the gitlab-runner process to do N number of builds and then go back offline. See: https://docs.gitlab.com/runner/commands/#gitlab-runner-run-single

... This is not zero-impact, but will definitely limit the blast radius of any problems.

zeathe
  • 41
  • 2
3

There currently isn't a solution for building on a specific runner in GitLab, but there is an issue open for Sticky Runners, which hopefully will be out in the next 3-6 months according to the Milestones!


The work around I've done so far to build a project on a specific runner is to use the GitLab Runner API, in a rather hacky way, along the lines of:

  • Get all project runners
  • As I know I've deployed the latest runner, that would have the highest runner "number"
  • Pause all the other runners associated with the project in question
  • Trigger the pipeline to build on the latest runner
  • Poll the GitLab API to get the status of the pipeline
  • Once that succeeds, resume all other runners!
  • If the pipeline fails, remember to resume the paused runners...
Rekovni
  • 3,672
  • 3
  • 26
  • 46
0

If you do not want to use tags another option could be to assign the runner to your specific projects. This option or the tag alternative are the way Gitlab is designed.

djuarezg
  • 1,795
  • 12
  • 28
  • 1
    Thanks for the answer, however I don't think I can use what you've suggested as that is already in use. I've updated the question to give more background! – Rekovni Nov 02 '17 at 10:30
  • @Rekovni Is this no tag policy something specific for your project? Because you always can change the tags afterwards and just add the tag on the .gitlab-ci.yml for only one pipeline run. – djuarezg Nov 02 '17 at 14:47
  • I'm doing this automated, so calling the pipeline using the Gitlab API. I don't think you can change the tags dynamically using the API? – Rekovni Nov 02 '17 at 15:10
  • @Rekovni Tags are specified on the .gitlab-ci.yml file and on the runners, so the answer is no, you can't essentially because they do not have tags. – djuarezg Nov 02 '17 at 16:21