【问题标题】:Prioritize some job instanciation inside a parallel stage在并行阶段内优先考虑一些作业实例化
【发布时间】:2021-09-28 17:38:28
【问题描述】:

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

由于 gitlab-runner 资源非常有限,所有的作业不能同时运行。 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 gitlab-ci gitlab-ci-runner


    【解决方案1】:

    可以通过使用以下关键字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
    

    【讨论】:

      【解决方案2】:

      您可以在 .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,您可以获得状态.. .

      【讨论】:

        猜你喜欢
        • 2019-09-20
        • 1970-01-01
        • 2015-08-27
        • 1970-01-01
        • 2011-06-09
        • 2017-08-27
        • 2015-12-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多