GitLab For 循环到每个事物的 运行 个阶段

GitLab For Loop to Run Stages for Each of a Thing

使用 Jenkins 声明式管道,您可以将映射循环到每个元素的 运行 个阶段:

https://newbedev.com/for-loop-in-jenkins-pipeline-code-example

有没有办法用 GitLab CI 做到这一点?

可以用矩阵,是一样的逻辑。

Here the doc about it.

我知道这已经得到回答,但我仍会添加一些细节等。一般来说,只有链接的答案不是好的答案,因为它们可能指向未来的任何地方。

正如@Joao Vitorino 正确指出的那样,有一个名为 matrix builds 的功能,可以通过

轻松实现
jobs:
  parallel:
    matrix:
      - ENVIRONMENT: 
        - 'test'
        - 'foo'
  script: echo $ENVIRONMENT

这将生成两个作业,一个用于 test,一个用于 foo,并打印出相应的选项。有关详细信息,请参阅:https://docs.gitlab.com/ee/ci/yaml/#parallel-matrix-jobs 您还可以执行多个变量和连接,例如:

  # copied from the official gitlab docs
  parallel:
    matrix:
      - PROVIDER: aws
        STACK:
          - monitoring
          - app1
          - app2
      - PROVIDER: ovh
        STACK: [monitoring, backup, app]
      - PROVIDER: [gcp, vultr]
        STACK: [data, processing]

这很可能会解决您所有的案件。除此之外,parallel:matrix 也适用于 trigger。这意味着您可以创建一个完整的管道,它将通过您的属性作为 child pipeline 触发,例如:

jobs:
  parallel:
    matrix:
      - ENVIRONMENT: 
        - 'test'
        - 'foo'
  trigger:
    include:
      - local: path/to/child-pipeline.yml
    strategy: depend

这将生成两个子管道,您可以在其中添加更多的步骤和逻辑,比普通的 matrix:parallel-builds

更简单