gitlab - 触发一个管道并等待另一个管道完成

标签 gitlab gitlab-ci

我有两个不同的项目存储库:我的应用程序存储库和 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/

相关文章:

docker - 无法设置文件修改时间,路径= './pubspec.lock'(操作系统错误:不允许操作,errno = 1)

oauth - GitLab 刷新 oAuth token

gitlab 在项目页面上显示错误的自述文件

git - Gitlab CI-通过SSH和git pull origin development进行部署不会执行

gitlab-ci - gitlab ci cd : get to know if branch or tag

azure - 使用 azure cli 将 gitlab 工件部署到 microsoft azure web 应用程序

docker - 在Gitlab CI/CD中,如何提交和发布正在运行我们阶段的docker容器

git - repo upload without review(repo推送功能)

docker - ERROR : Registering runner. 禁止(检查注册 token )

yaml - 无法在 gitlab ci yaml 文件中的作业之间共享全局变量值