Reputation: 1230
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?
Upvotes: 19
Views: 9082
Reputation: 557
Gitlab CI assign jobs to those runners which are available. If a runner is not available because of being 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/machine 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 that^'s the benefit of the runner/docker architecture.
Upvotes: 4
Reputation: 1055
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 x
amount of ms
it 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
Upvotes: 11