我需要像这样配置我的 GitLab CI 作业:
- 只有带有
$CI_PIPELINE_SOURCE == "merge_request_event"
的作业被添加到 Pipeline, - 对于由矩阵
PHP_VERSION: [ '7.4', '8.0', '8.1' ]
定义的每个版本,作业由matrix
多次运行。 '8.1'
必须以allow_failure: true
运行。
我尝试编写直观的规则,因为除了规则有效,但我得到了不同的结果。
我首先尝试了这个:
parallel:
matrix:
- PHP_VERSION: [ '7.4', '8.0', '8.1' ]
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$PHP_VERSION == "8.1"'
allow_failure: true
它只对我们添加到管道的 PHP 8.1 的 MR 事件产生结果。
我的下一次迭代仍然是错误的:
parallel:
matrix:
- PHP_VERSION: [ '7.4', '8.0', '8.1' ]
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$PHP_VERSION == "8.1"'
when: on_success
allow_failure: true
- when: on_success
这看起来更好,但它会为每个其他事件运行作业(不仅是 merge_request_event
)。
我如何正确组合规则以获得我上面声明的结果? 🙏
最佳答案
你可以试试
parallel:
matrix:
- PHP_VERSION: [ '7.4', '8.0', '8.1' ]
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: on_success
- if: '$PHP_VERSION == "8.1"'
when: on_success
allow_failure: true
- if: '$PHP_VERSION'
when: on_success
allow_failure: false
基于 https://docs.gitlab.com/ee/ci/jobs/job_control.html#run-a-matrix-of-parallel-trigger-jobs
执行示例
关于gitlab-ci - 如何为规则 :if with matrix and allow_failure? 组合 GitLab CI 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71077141/