Gitlab CI 可以触发其他项目流水线阶段吗?
Gitlab CI can trigger other project pipeline stage?
我有一个A项目和一个E2E项目。我想部署一个项目触发 E2E 管道 运行 测试,但我只想要触发测试阶段。我们不需要触发 E2E 来构建部署...等等
e2e_tests:
stage: test
trigger:
project: project/E2E
branch: master
strategy: depend
stage: test
我试过在配置中使用舞台。但得到错误未知键:stage
有什么建议吗?
在您的 E2E 项目中,接收触发器的项目中,您可以使用 rules
语法告诉作业仅 运行 当管道源是触发器时:
build-from-trigger:
stage: build
when: never
rules:
- if: "$CI_COMMIT_REF_NAME == 'master' && $CI_PIPELINE_SOURCE == 'trigger'
when: always
script:
- ./build.sh # this is just an example, you'd run whatever you normally would here
第一个 when
语句,when: never
设置作业的默认值。默认情况下,此作业永远不会 运行。然后使用 rule
语法,我们设置允许作业 运行 的条件。如果 CI_COMMIT_REF_NAME
变量(分支或标签名称)是 master
并且 CI_PIPELINE_SOURCE
变量(从该管道开始的任何东西)是 trigger
,那么我们 运行 这份工作。
您可以在此处阅读有关 when
关键字的信息:https://docs.gitlab.com/ee/ci/yaml/#when, and you can read the rules
documentation here: https://docs.gitlab.com/ee/ci/yaml/#rules
我有一个A项目和一个E2E项目。我想部署一个项目触发 E2E 管道 运行 测试,但我只想要触发测试阶段。我们不需要触发 E2E 来构建部署...等等
e2e_tests:
stage: test
trigger:
project: project/E2E
branch: master
strategy: depend
stage: test
我试过在配置中使用舞台。但得到错误未知键:stage
有什么建议吗?
在您的 E2E 项目中,接收触发器的项目中,您可以使用 rules
语法告诉作业仅 运行 当管道源是触发器时:
build-from-trigger:
stage: build
when: never
rules:
- if: "$CI_COMMIT_REF_NAME == 'master' && $CI_PIPELINE_SOURCE == 'trigger'
when: always
script:
- ./build.sh # this is just an example, you'd run whatever you normally would here
第一个 when
语句,when: never
设置作业的默认值。默认情况下,此作业永远不会 运行。然后使用 rule
语法,我们设置允许作业 运行 的条件。如果 CI_COMMIT_REF_NAME
变量(分支或标签名称)是 master
并且 CI_PIPELINE_SOURCE
变量(从该管道开始的任何东西)是 trigger
,那么我们 运行 这份工作。
您可以在此处阅读有关 when
关键字的信息:https://docs.gitlab.com/ee/ci/yaml/#when, and you can read the rules
documentation here: https://docs.gitlab.com/ee/ci/yaml/#rules