gitlab-ci - 如何为规则 :if with matrix and allow_failure? 组合 GitLab CI 作业

标签 gitlab-ci pipeline

我需要像这样配置我的 GitLab CI 作业:

  1. 只有带有 $CI_PIPELINE_SOURCE == "merge_request_event" 的作业被添加到 Pipeline,
  2. 对于由矩阵 PHP_VERSION: [ '7.4', '8.0', '8.1' ] 定义的每个版本,作业由 matrix 多次运行。
  3. '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

执行示例

enter image description here

关于gitlab-ci - 如何为规则 :if with matrix and allow_failure? 组合 GitLab CI 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71077141/

相关文章:

image - gitlab ci yml 图像和服务机制?

bash - jq : command not found in GitLab CI file

json - 来自 JSON 文件的 Powershell Out-GridView

linux - 如何将(两个)管道指令的输出传递给文件?

java - 是否从 akka i/o 中删除了管道?

amazon-web-services - Github 工作流 CI/CD 失败

windows - 使用 Windows 命令行将多行环境变量回显到文本文件

node.js - 从 gitlab 安装 NPM 包不会仅在 CI 上下载所有 repo 文件

batch-file - Windows 上的 GitLab runner 和处理 & %ERRORLEVEL%

jenkins - 缺少必需的上下文类hudson.FilePath也许您忘记了用提供此功能的步骤来包围代码,例如: node