“.gitlab-ci.yml”:如何在"trigger"中定义多个项目?

".gitlab-ci.yml": how to define multiple projects in "trigger"?

我有一个项目“my_project_0”,它必须触发我所有其他项目(“my_project_1”、“my_project_2”等)的管道。

我想要的:

  stage: multi_project_test
  trigger:
    project: "my_project_1"
    strategy: depend
  trigger:
    project: "my_project_2"
    strategy: depend
  trigger:
    project: "my_project_3"
    strategy: depend

...但我有错误 Key 'trigger' is duplicated

关于Multi-project pipelines的官方页面没有用,因为它没有多项目管道的示例(仅用于父子触发器)。

触发多个项目管道的正确语法是什么?

您必须为要触发的每个下游管道创建桥接作业。

例如:

downstream 1/3:
  stage: multi_project_test
  trigger:
    project: project-1
    strategy: depend

downstream 2/3:
  stage: multi_project_test
  trigger:
    project: project-2
    strategy: depend

downstream 3/3:
  stage: multi_project_test
  trigger:
    project: project-3
    strategy: depend

我还没有测试过这个,但是你应该能够使用parallel:matrix以简洁的方式定义与上面相同的东西:

downstream_pipelines:
  stage: multi_project_test
  parallel:
    matrix:
      - DOWNSTREAM_PROJECT: ["project-1", "project-2", "project-3"]
  trigger:
    project: $DOWNSTREAM_PROJECT
    strategy: depend