ZBLOG

gitlab ci 获取sonar结果阻止提交

您可以在 GitLab CI 配置文件中添加一个阶段,以获取 Sonarqube 的分析结果,并在结果未达到预期标准时阻止提交。

以下是示例 GitLab CI 配置文件:

stages:
  - build
  - test
  
build:
  stage: build
  script:
    - your build command here

test:
  stage: test
  script:
    - sonar-scanner # run Sonarqube analysis
    - sonar-quality-gate # check if analysis results meet quality gate threshold
  rules:
    - if: $CI_COMMIT_BRANCH == "master" # only run on master branch
      when: always # always run, even if previous stages failed
      allow_failure: false # fail pipeline if Sonarqube quality gate not met

该配置文件定义了两个阶段:构建和测试。在测试阶段,它运行了 Sonarqube 分析并使用 sonar-quality-gate 命令检查结果是否符合质量门限。如果结果未达到预期标准,则阻止提交。注意,此配置仅在主分支上运行,失败时不允许继续执行。

您可以根据自己的需求修改配置文件,例如更改质量门限或将其应用于其他分支。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=124

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?