【问题标题】:GitLab CI: Two independent scheduled jobsGitLab CI:两个独立的计划作业
【发布时间】:2019-11-03 07:50:14
【问题描述】:

考虑以下gilab-ci.yml 脚本:

stages:
  - build_for_ui_automation
  - independent_job

variables:
  LC_ALL: "en_US.UTF-8"
  LANG: "en_US.UTF-8"

before_script:
  - gem install bundler
  - bundle install

build_for_ui_automation:
  dependencies: []
  stage: build_for_ui_automation
  artifacts:
    paths:
      - fastlane/screenshots
      - fastlane/logs
      - fastlane/test_output
      - fastlane/report.xml
  script:
    - bundle exec fastlane ui_automation
  tags:
    - ios
  only:
    - schedules
  allow_failure: false

# This should be added and trigerred independently from "build_for_ui_automation"
independent_job:
  dependencies: []
  stage: independent_job
  artifacts:
    paths:
      - fastlane/screenshots
      - fastlane/logs
      - fastlane/test_output
      - fastlane/report.xml
  script:
    - bundle exec fastlane independent_job
  tags:
    - ios
  only:
    - schedules
  allow_failure: false

我希望能够独立安排这两个工作,但要遵守规则:

  • build_for_ui_automation 每天在 5 AM 运行
  • independent_job 每天在 下午 5 点运行

但是,在当前设置下,我只能触发整个管道,这将依次执行两个作业。

我怎样才能有一个只触发一个作业的计划?

【问题讨论】:

    标签: gitlab gitlab-ci gitlab-ci-runner gitlab-ce


    【解决方案1】:

    要构建@Naor Tedgi 的答案,您可以在管道计划中定义一个变量。例如,在 build_for_ui_automation 的计划中设置 SCHEDULE_TYPE = "build_ui",在 Independent_job 的计划中设置 SCHEDULE_TYPE = "independent"。那么你的.gitlab-ci.yml文件可以修改为:

    stages:
      - build_for_ui_automation
      - independent_job
    
    variables:
      LC_ALL: "en_US.UTF-8"
      LANG: "en_US.UTF-8"
    
    before_script:
      - gem install bundler
      - bundle install
    
    build_for_ui_automation:
      dependencies: []
      stage: build_for_ui_automation
      artifacts:
        paths:
          - fastlane/screenshots
          - fastlane/logs
          - fastlane/test_output
          - fastlane/report.xml
      script:
        - bundle exec fastlane ui_automation
      tags:
        - ios
      only:
        refs:
          - schedules
        variables:
          - $SCHEDULE_TYPE == "build_ui"
      allow_failure: false
    
    # This should be added and trigerred independently from "build_for_ui_automation"
    independent_job:
      dependencies: []
      stage: independent_job
      artifacts:
        paths:
          - fastlane/screenshots
          - fastlane/logs
          - fastlane/test_output
          - fastlane/report.xml
      script:
        - bundle exec fastlane independent_job
      tags:
        - ios
      only:
        refs:
          - schedules
        variables:
          - $SCHEDULE_TYPE == "independent"
      allow_failure: false
    

    注意only 部分中的语法更改,以仅在计划期间和计划变量匹配时执行作业。

    【讨论】:

    • 这是我采用的解决方案。
    【解决方案2】:

    在你项目中的 gitlab 中转到 CI/CD -> Schedules 按新的计划按钮配置您想要的任务设置时间和间隔

    现在在最后为每个变量添加一个变量

    现在通过在only 部分添加该变量来编辑您的 gitlab.yml

    如下图所示

    https://docs.gitlab.com/ee/ci/variables/#environment-variables-expressions

    【讨论】:

      猜你喜欢
      • 2021-11-17
      • 2021-05-05
      • 1970-01-01
      • 2021-05-06
      • 2023-03-14
      • 2018-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多