优先考虑并行阶段中的一些作业实例化

Prioritize some job instanciation inside a parallel stage

我的管道继承(使用 include)公司管道。我的管道中有顺序阶段,最后一个阶段包含三个作业:

由于 gitlab-运行ner 的资源非常有限,所有作业不能同时 运行。 Gitlab 似乎在同一阶段按字母顺序启动作业。

作业“sonarqube”是最受期待的作业 运行 首先,如何在保持并行的同时将其实例化优先于其他作业?

在我的 .gitlab-ci.yml 中,作业已按预期顺序覆盖,但这不起作用:

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

# ...

sonarqube:
  stage: analysis

license-finder:
  allow_failure: true

checkmarx:
  dependencies: []
  timeout: 1 hours

你有线索吗?

您可以在 .gitlab-ci.yml 中使用 resource_group attribute 限制并行度,但不要认为这可以准确满足您的需求... 也许您可以将这些作业配置为手动并在之前的作业中使用 API call 触发它们?类似于:

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

call_jobs:
  script:
    # execute first job
    - curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/jobs/1/play"
    - sleep 60
    # execute the second job after some time 
    .....

sonarqube:
  stage: analysis
  when: manual

license-finder:
  allow_failure: true
  when: manual

checkmarx:
  dependencies: []
  timeout: 1 hours
  when: manual

您甚至可以获得最昂贵的工作的状态,并在完成后触发其他两个... 使用 GET /projects/:id/pipelines/:pipeline_id/jobs 你可以获得最昂贵的工作的 ID(不能使用 JOB_ID 环境变量,因为你不在你想要获取 ID 的工作中!)然后使用 GET /projects/:id/jobs/:job_id 你可以得到状态...

使用以下关键字 when: delayedstart_in: x seconds

可以通过延迟其他作业来优先处理某些作业

这是一个工作示例:

sonarqube:
  stage: analysis

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

checkmarx:
  stage: analysis
  when: delayed
  start_in: 1 seconds