gitlabgitlab-cigitlab-ci-runnergitlab-omnibus

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?


Solution

  • 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