GitLab CI:两个独立的预定作业

GitLab CI: Two independent scheduled jobs

考虑以下 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

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

但是,在当前设置下,我只能触发整个管道,这将按顺序完成两个作业。

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

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

现在在最后为它们中的每一个添加一个变量

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

如下图所示

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

要建立@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 部分中的语法更改,以便仅在计划期间和计划变量匹配时执行作业。