12

Consider the following gilab-ci.yml script:

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

I'd like to be able to schedule these two jobs independently, but following the rules:

  • build_for_ui_automation runs every day at 5 AM
  • independent_job runs every day at 5 PM

However, with the current setup I can only trigger the whole pipeline, which will go through both jobs in sequence.

How can I have a schedule triggering only a single job?

4

2 回答 2

7

要构建@Naor Tedgi 的答案,您可以在管道计划中定义一个变量。例如,SCHEDULE_TYPE = "build_ui"在 build_for_ui_automation 的计划和 Independent_jobSCHEDULE_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部分中的语法更改以仅在计划期间和计划变量匹配时执行作业。

于 2020-11-17T15:55:55.570 回答
5

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

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

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

如下图所示

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

于 2019-06-20T13:30:06.323 回答