我有两个不同的项目存储库:我的应用程序存储库和 API 存储库。我的应用程序与 API 进行通信。
我想为我的应用程序设置一些集成和端到端测试。运行这些测试时,应用程序需要使用最新版本的 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 管道进行排队(两个项目都使用相同的运行器)并在 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 管道在进入集成测试阶段之前运行并完成。
有办法做到这一点吗?
最佳答案
我最近遇到了这个限制,并设置了一个可以重复使用的图像,以使其成为一个简单的构建步骤:
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)并创建一个个人访问 token ,您可以在此处提供该 token (最好通过 secret 来执行此操作)。
需要后者的原因是为了轮询管道状态。没有它也可以触发,但获取结果需要 API 授权。
有关更多详细信息以及 pipeline-trigger 可以执行的其他操作,请参阅项目描述。
关于gitlab - 触发一个管道并等待另一个管道完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44336447/