首页 > 解决方案 > 允许基于 `if` 和 `changes` 子句手动运行作业

问题描述

我的rules一项工作有以下内容:

rules:
  - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "develop"'
    changes:
      - upstream/**/*.*

  - when: manual
  - allow_failure: false

当前的行为是这样的(伪代码):

if (on master or develop) and (there are upstream changes):
  run_job_automatically
else
  permit_running_job_manually

我想要这个:

if (on master or develop) and (there are upstream changes):
  permit_running_job_manually
else
  dont_show_job

wheredont_show_job指的是首先不使工作成为管道的一部分。

换句话说,我希望将the与 and子句when: manual结合起来,而不是作为替代。该作业要么允许手动运行,要么根本不显示。它永远不应该自动运行。ifchanges

那可能吗?

标签: continuous-integrationgitlabgitlab-ci

解决方案


您可以在块中使用手动块if来做您想做的事情,我相信:

rules:
  - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "develop"'
    changes:
      - upstream/**/*.*
    when: manual
    allow_failure: false

更多规则属性


推荐阅读