如果测试作业在另一个存储库中失败,则gitlab多作业管道失败
我的应用程序repo中有一个gitlab ci管道,它调用端到端测试repo T来运行测试。repo A管道成功地从repo T触发测试,但是如果测试作业在T中失败,则从A调用T中测试作业的作业仍然通过。如何让RepoA跟踪RepoT测试作业的结果,并根据T中的测试作业通过/失败其管道 .gitlab-ci.yml用于测试报告:如果测试作业在另一个存储库中失败,则gitlab多作业管道失败,gitlab,gitlab-ci,Gitlab,Gitlab Ci,我的应用程序repo中有一个gitlab ci管道,它调用端到端测试repo T来运行测试。repo A管道成功地从repo T触发测试,但是如果测试作业在T中失败,则从A调用T中测试作业的作业仍然通过。如何让RepoA跟踪RepoT测试作业的结果,并根据T中的测试作业通过/失败其管道 .gitlab-ci.yml用于测试报告: stages: - test test: stage: test image: markhobson/maven-chrome:jdk-11 arti
stages:
- test
test:
stage: test
image: markhobson/maven-chrome:jdk-11
artifacts:
paths:
- target/surefire-reports
script:
- mvn test
only:
- triggers
.gitlab-ci.yml来自应用程序回购A:
job1:
stage: unit-tests ...
job2:
stage: build ...
...
trigger-e2e-repo:
stage: e2e-testing
image: markhobson/maven-chrome
script:
- "curl -X POST -F token=repo-T-token -F ref=repo-T-branch https://repo-A/api/v4/projects/repo-T-id/trigger/pipeline"
only:
- repo-A-branch
由于GitLab 11.8,您可以通过触发管道 在GitLab 11.8中,GitLab提供了一种新的CI/CD配置语法,以简化此任务,并避免需要GitLab Runner来触发跨项目管道 通过桥接作业,可以连接到调用管道 您可以使用策略:depend将已触发管道的管道状态镜像到源网桥作业 你的例子是:
trigger-e2e-repo:
stage: e2e-testing
trigger: repo-T
strategy: depend
如果带有测试作业的触发管道失败,则调用管道也会失败
如果在由桥接作业执行时只希望在存储库“Repo T”中执行特定作业,则应使用
only:pipeline
()或规则:-If'$CI_pipeline_SOURCE==“pipeline”
()我无法使用镜像下游作业结果的桥接作业属性,而不是only:triggers
,因为我的gitlab版本在11.8之前。我为回购a创建了一个触发器,并用这个新的第二个触发器从回购T向回购a发出了一个调用,从而成功地实现了它。回购协议A中的剩余作业将仅通过触发器和变量设置(本例中为作业)激活,如下所示:
.gitlab-ci.yml用于回购:
test:
stage: test
script:
- mvn test
- "curl -X POST -F token=repo-A-token -F ref=$BRANCH -F variables[JOB]=build https://project.com/api/v4/projects/project_id/trigger/pipeline"
.gitlab-ci.yml
job1:
...
except:
- triggers
job2:
...
except:
- triggers
...
trigger-e2e-repo:
stage: e2e-testing
script:
- "curl -X POST -F token=repo-B-token -F ref=repo-B-branch -F variables[BRANCH]=$CI_COMMIT_REF_NAME -F https://project-B/api/v4/projects/project-B-id/trigger/pipeline"
except:
- triggers
build_application_for_prod:
stage: build_prod
script:
- "curl -X POST -F token=repo-A-token -F ref=$CI_COMMIT_REF_NAME -F variables[JOB]=deploy -F variables[SEND]=true https://foo/api/v4/projects/proj_A_id/trigger/pipeline"
only:
variables:
- $JOB == "build"
deploy_production_environment:
stage: deploy_prod
script:
- ...
only:
variables:
- $JOB == "deploy"
注意:我还必须在repo A中的端到端测试之前为作业添加
语句,以便它们不会在稍后调用repo A的API触发器时重新运行和循环。这很好。我会将其标记为答案,但我无法使用此解决方案,因为我的gitlab版本早于11.8。我确实设法破解了一个变通方法,我将在下面发布。