Search code examples
gitlabgitlab-cigitlab-ci-runner

Prioritize some job instanciation inside a parallel stage


My pipeline inherit (with include) from a corporate pipeline. There are sequential stages in my pipeline and the final one contains three jobs:

There are 2 of 3 running parallel jobs inside the same stage

Since the gitlab-runner is very resources limited, all the jobs can't be run in the same time. Gitlab seems to launch the job in alphebetical order inside a same stage.

The job "sonarqube" is the most expected job to be run first, how to prioritize its instantiation over the others while still keeping them in parallel?

In my .gitlab-ci.yml the jobs are already overriden in the expected order but this does not work:

include:
  - project: "project/parent"
    ref: production
    file: "main.yml"

# ...

sonarqube:
  stage: analysis

license-finder:
  allow_failure: true

checkmarx:
  dependencies: []
  timeout: 1 hours

Do you have any leads?


Solution

  • It is possible to prioritize some jobs by delaying the others with the following keywords when: delayed and start_in: x seconds.

    Here is a working example:

    sonarqube:
      stage: analysis
    
    license-finder:
      stage: analysis
      when: delayed
      start_in: 1 seconds
    
    checkmarx:
      stage: analysis
      when: delayed
      start_in: 1 seconds