Gitlab 如何有条件地执行Git Lab管道作业,或在不同键之间建立关系;只有";参数

Gitlab 如何有条件地执行Git Lab管道作业,或在不同键之间建立关系;只有";参数,gitlab,gitlab-ci,Gitlab,Gitlab Ci,尽管围绕GitLab CI管道的条件作业执行有许多问题和答案,但我找不到解决问题的方法:当某些文件发生更改时,从管道触发特定作业或,环境变量设置为特定值。大概是这样的: job_build: tags: - executor-shell stage: build script: - ./gitlab_ci_helper.sh build only: changes: - /path/to/files/with/changes/*

尽管围绕GitLab CI管道的条件作业执行有许多问题和答案,但我找不到解决问题的方法:当某些文件发生更改时,从管道触发特定作业,环境变量设置为特定值。大概是这样的:

job_build:

  tags:
    - executor-shell

  stage:
    build

  script:
    - ./gitlab_ci_helper.sh build

  only:
    changes:
      - /path/to/files/with/changes/*
    variables:
      - $BUILD_IS_A_MUST == "TRUE"
job_build:

  tags:
    - executor-shell

  stage:
    build

  script:
    - ./gitlab_ci_helper.sh build

  rules:
    - changes:
      - /path/to/files/with/changes/*
      when: on_success
    - if: $BUILD_IS_A_MUST == "TRUE"
      when: on_success
根据GitLab本身提供的信息,我们有以下内容:


现在我的问题是如何使条件
不是(任何变量)和(任何变化))
,它与
(任何变量)或(任何变化)
相同,但只适用于
参数?

好吧,最后,我似乎找到了问题的答案。事实证明,从GitLab版本12.3开始,引入了一个新的配置参数,名为

看起来这个参数正好解决了我一直在寻找答案的问题。虽然我还没有GitLab 12.3版本来测试它,但上面的ci作业将更改为如下内容:

job_build:

  tags:
    - executor-shell

  stage:
    build

  script:
    - ./gitlab_ci_helper.sh build

  only:
    changes:
      - /path/to/files/with/changes/*
    variables:
      - $BUILD_IS_A_MUST == "TRUE"
job_build:

  tags:
    - executor-shell

  stage:
    build

  script:
    - ./gitlab_ci_helper.sh build

  rules:
    - changes:
      - /path/to/files/with/changes/*
      when: on_success
    - if: $BUILD_IS_A_MUST == "TRUE"
      when: on_success

在这种情况下,默认规则将被解析为
when:never
,这是我所追求的,因此不需要指定它。

只是为了确认上面也进行了测试,并且它确实按照预期工作。