Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does gitlab decide which runner to use for a job

If there are more than one available runner for a project, how does gitlab ci decide which runner to use?

I have an omnibus gitlab 8.6.6-ee installation, with 2 runners configured. The runners are identical (docker images, config, etc) except that they are running on different computers.

If they are both idle and a job comes in that either of them could run, which one will run?

like image 796
BM5k Avatar asked Apr 18 '16 17:04

BM5k


People also ask

Which executor does GitLab runner use?

The Shell executor is a simple executor that you use to execute builds locally on the machine where GitLab Runner is installed. It supports all systems on which the Runner can be installed.

Can a GitLab runner run multiple jobs?

One way to allow more jobs to run simultaneously is to simply register more runners. Each installation of GitLab Runner can register multiple distinct runner instances. They operate independently of each other and don't all need to refer to the same coordinating server.

How many GitLab runners do I need?

You can have one gitlab runner for all stages. The build job would then be picked up by any gitlab runner that you have defined that has the tag build .


2 Answers

To add to Rubinum's answer the 'first' runner would be whichever runner that checks in first that meets all criteria. For example, labels could limit which runners certain jobs run on.

Runners query the gitlab server every X seconds to check if there are builds. if there's a build queued and multiple meet criteria, the first to ask will win

Update to answer comments:

Runners communicate through the CI API http://docs.gitlab.com/ce/ci/api/builds.html to get build status. This will eventually imply that it will become a more or less random choosing of the runner based on when it finished the last job and the xamount of msit is waiting to check.

To completely answer the question:

Credit goes to BM5k after digging through the code and finding that x = 3 seconds based on this and this. Also found that:

which machine a docker+machine runner will use once that runner has been selected) reveals that the machine selection is more or less (effectively) random as well

like image 168
Jose Torres Avatar answered Oct 20 '22 05:10

Jose Torres


Gitlab CI assign jobs to those runners which are available. If a runner is not availble because of beeing busy then Gitlab CI assign the job to other runners which are available. In your case it will always assign the jobs to the first runner (whoever it is).

If you want to specify the execution on a specific runner/mashine then have a look at my post here.

In my opinion its good to not know which runner will run your build if you are using docker because thats the benefit of the runner/docker archeticture.

like image 32
Rubinum Avatar answered Oct 20 '22 07:10

Rubinum