Rekovni
Rekovni

Reputation: 7344

GitLab: Is it possible to run pipeline on a specific runner?

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.

Upvotes: 28

Views: 39910

Answers (3)

zeathe
zeathe

Reputation: 51

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.

Upvotes: 5

Rekovni
Rekovni

Reputation: 7344

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...

Upvotes: 4

djuarezg
djuarezg

Reputation: 2541

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.

Upvotes: 2

Related Questions