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

Ric*_*hiy 9 gitlab gitlab-ci gitlab-ci-runner gitlab-ce

考虑以下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
Run Code Online (Sandbox Code Playgroud)

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

  • build_for_ui_automation每天早上5 点运行
  • Independent_job每天下午5 点运行

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

我怎样才能有一个只触发一个工作的时间表?

Ale*_*exM 21

注意- 此答案使用GitLab CI 来操纵将哪些作业添加到计划中。然而,截至今天,GitLab 已停止对相同命令的主动维护,并建议我们改用规则。这是链接

我已经修改了原来的答案以使用规则并测试了工作。

为了构建 @Naor Tedgi 的答案,您可以在管道计划中定义一个变量。例如,SCHEDULE_TYPE = "build_ui"在 build_for_ui_automation 的计划中和SCHEDULE_TYPE = "independent"independent_job 的计划中设置。然后你的.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
Run Code Online (Sandbox Code Playgroud)

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

  • 这是我采用的解决方案。 (2认同)

Nao*_*dgi 8

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

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

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

如下所示

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