在我的应用程序repo,A中有一个gitlab ci管道,它调用一个端到端测试Repo来运行它的测试。repo A管道成功地从Repo T触发测试,但是如果测试作业在T中失败,则从A调用T中的测试作业仍然通过。如何使回购A跟踪repo T的测试作业结果,并根据T中的测试作业通过/失败其管道?
..gitlab ci.yml用于测试Repo T:
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发布于 2021-04-01 21:15:54
由于GitLab 11.8,您可以通过桥梁作业触发管道。
在GitLab 11.8中,GitLab提供了一个新的CI/CD配置语法,以简化这项任务,并避免需要GitLab Runner来触发跨项目管道。
有了桥作业,就可以镜像触发管道的状态。到调用管道。
您可以使用策略:依赖将触发管道的管道状态镜像到源桥作业。
在您的例子中:
trigger-e2e-repo:
stage: e2e-testing
trigger:
project: repo-T
strategy: depend如果带有测试作业的触发管道失败,则调用管道也将失败。
如果您只想在由桥作业执行时在存储库"Repo“中执行特定的作业,则应该使用only: pipeline (仅限)或rules: -if '$CI_PIPELINE_SOURCE == "pipeline"' (规则:如果)而不是only: triggers。
发布于 2021-04-01 22:29:03
我无法使用映射下游作业结果的桥作业属性,因为我的gitlab版本在11.8之前。我为回购A创建了一个触发器,并用这个新的第二个触发器从repo T调用了repo A。回购A中的其余作业将仅由触发器和变量设置(在本例中为JOB)激活,如下所示:
..gitlab ci.yml用于回购T:
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在A
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中的结束测试之前为作业添加except语句,这样它们就不会在稍后调用repo的API触发器时重新运行和循环。
https://stackoverflow.com/questions/66909047
复制相似问题