触发管道并等待它从另一个管道完成
Triggering a pipeline and waiting for it to finish from another pipeline
我有两个不同的项目存储库:我的应用程序存储库和一个 API 存储库。我的应用程序与 API.
通信
我想为我的应用程序设置一些集成和 E2E 测试。 运行进行这些测试时,应用程序需要使用最新版本的 API 项目。
API 项目已设置为在触发时部署
deploy_integration_tests:
stage: deploy
script:
- echo "deploying..."
environment:
name: integration_testing
only:
- triggers
我的应用程序有一个这样设置的集成测试作业:
integration_test
stage: integration_test
script:
- echo "Building and deploying API..."
- curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
- echo "Now running the integration test that depends on the API deployment..."
我遇到的问题是触发器仅对 API 管道进行排队(两个项目都使用相同的 运行ner)并在 API 管道实际 运行.
有没有办法在尝试 运行 集成测试之前等待 API 管道到 运行?
我可以这样做:
integration_test_dependency
stage: integration_test_dependency
script:
- echo "Building and deploying API..."
- curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
integration_test
stage: integration_test
script:
- echo "Now running the integration test that depends on the API deployment..."
但这仍然不能保证 API 管道 运行 在进入 integration_test 阶段之前完成。
有办法吗?
目前这是不可能的。 gitlab中有一些关于这个的问题:
- https://gitlab.com/gitlab-org/gitlab-ce/issues/25457
- https://gitlab.com/gitlab-org/gitlab-ce/issues/29347
- https://gitlab.com/gitlab-org/gitlab-ce/issues/22972
- 等等
最好的办法是重视其中的一些问题。
我缺少完全相同的功能,所以我写了一个 python3 实用程序来完成它。
我最近遇到了这个限制,并设置了一个可以重复使用的图像,使这个构建步骤变得简单:
https://gitlab.com/finestructure/pipeline-trigger
所以在你的情况下,使用我的图像看起来像这样:
integration_test
stage: integration_test
image: registry.gitlab.com/finestructure/pipeline-trigger
script:
- echo "Now running the integration test that depends on the API deployment..."
- trigger -a <api token> -p <token> <project id>
只需使用项目 ID(而不是必须找到整个 url)并创建一个个人访问令牌,您可以在此处提供(最好通过秘密进行此操作)。
之所以需要后者是为了轮询管道状态。您可以在没有它的情况下触发,但要获得结果需要 API 授权。
有关更多详细信息和管道触发器可以执行的其他操作,请参阅项目描述。
如果其他人在这里从 ci yaml 的触发管道上寻找这个,您可以使用关键字 depend
for strategy
以确保管道等待触发管道:
trigger:
project: group/triggered-repo
strategy: depend
我有两个不同的项目存储库:我的应用程序存储库和一个 API 存储库。我的应用程序与 API.
通信我想为我的应用程序设置一些集成和 E2E 测试。 运行进行这些测试时,应用程序需要使用最新版本的 API 项目。
API 项目已设置为在触发时部署
deploy_integration_tests:
stage: deploy
script:
- echo "deploying..."
environment:
name: integration_testing
only:
- triggers
我的应用程序有一个这样设置的集成测试作业:
integration_test
stage: integration_test
script:
- echo "Building and deploying API..."
- curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
- echo "Now running the integration test that depends on the API deployment..."
我遇到的问题是触发器仅对 API 管道进行排队(两个项目都使用相同的 运行ner)并在 API 管道实际 运行.
有没有办法在尝试 运行 集成测试之前等待 API 管道到 运行?
我可以这样做:
integration_test_dependency
stage: integration_test_dependency
script:
- echo "Building and deploying API..."
- curl.exe -X POST -F token=<token> -F ref=develop <url_for_api_trigger>
integration_test
stage: integration_test
script:
- echo "Now running the integration test that depends on the API deployment..."
但这仍然不能保证 API 管道 运行 在进入 integration_test 阶段之前完成。
有办法吗?
目前这是不可能的。 gitlab中有一些关于这个的问题:
- https://gitlab.com/gitlab-org/gitlab-ce/issues/25457
- https://gitlab.com/gitlab-org/gitlab-ce/issues/29347
- https://gitlab.com/gitlab-org/gitlab-ce/issues/22972
- 等等
最好的办法是重视其中的一些问题。
我缺少完全相同的功能,所以我写了一个 python3 实用程序来完成它。
我最近遇到了这个限制,并设置了一个可以重复使用的图像,使这个构建步骤变得简单:
https://gitlab.com/finestructure/pipeline-trigger
所以在你的情况下,使用我的图像看起来像这样:
integration_test
stage: integration_test
image: registry.gitlab.com/finestructure/pipeline-trigger
script:
- echo "Now running the integration test that depends on the API deployment..."
- trigger -a <api token> -p <token> <project id>
只需使用项目 ID(而不是必须找到整个 url)并创建一个个人访问令牌,您可以在此处提供(最好通过秘密进行此操作)。
之所以需要后者是为了轮询管道状态。您可以在没有它的情况下触发,但要获得结果需要 API 授权。
有关更多详细信息和管道触发器可以执行的其他操作,请参阅项目描述。
如果其他人在这里从 ci yaml 的触发管道上寻找这个,您可以使用关键字 depend
for strategy
以确保管道等待触发管道:
trigger:
project: group/triggered-repo
strategy: depend