0

如何设置适用于管道中所有作业/步骤的变量或配置?我正在使用自动 Devops。

目前,我使用如下,但我想将重试配置应用于管道中的所有作业,而不是为每个作业指定它,如下所示。有没有办法做到这一点 ?

build:
  retry:
    max: 2
    when:
      - runner_system_failure
      - stuck_or_timeout_failure
      - scheduler_failure
      - stale_schedule
      - unknown_failure

review:
  retry:
    max: 2
    when:
      - runner_system_failure
      - stuck_or_timeout_failure
      - scheduler_failure
      - stale_schedule
      - unknown_failure
4

1 回答 1

2

如果要使用变量,可以在 yaml 的基础级别应用它,它将应用于该 CI/CD 中的所有作业。如果您想应用更通用的内容(例如示例中的重试),请使用带有“extends”关键字的 yml 锚。这是两件事的一个例子:

variables:
  EVERY_JOB_VARIABLE: "hello world"

.anchor_retry:
  retry:
    max: 2
    when:
      - runner_system_failure
      - stuck_or_timeout_failure
      - scheduler_failure
      - stale_schedule
      - unknown_failure

build:
  extends: .anchor_retry
  script:
    - echo $EVERY_JOB_VARIABLE # prints "hello world"

review:
  extends: .anchor_retry
  script:
    - echo $EVERY_JOB_VARIABLE # prints "hello world"

于 2021-10-08T01:55:56.543 回答