考虑以下
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 的 only- except 来操作将哪些作业添加到计划中。然而,截至今天,GitLab 已停止对相同命令的主动维护,并建议我们改用rules。这是链接。
我已经修改了原来的答案以使用rules并测试了工作。
为了构建@Naor Tedgi 的答案,您可以在管道计划中定义一个变量。例如,在 build_for_ui_automation 的计划中设置
SCHEDULE_TYPE = "build_ui"
,在独立_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
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "build_ui"'
when: always
variables:
SCHEDULE_TYPE: "build_ui"
ANOTHER_VARIABLE: "dummy"
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
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "independent"'
when: always
variables:
SCHEDULE_TYPE: "independent"
ANOTHER_VARIABLE: "dummy123"
allow_failure: false
请注意
only
部分中的语法更改,以便仅在计划期间以及计划变量匹配时执行作业。
在项目内的 gitlab 中转到
CI/CD
-> Schedules
按新的计划按钮根据需要配置任务设置时间和间隔
现在在最后为每个变量添加一个变量
现在通过在
only
部分添加该变量来编辑 gitlab.yml
如下图所示
https://docs.gitlab.com/ee/ci/variables/#environment-variables-expressions