简体   繁体   English

如何从 Jenkins 管道中的 SonarQube 接收质量门状态?

[英]How to receive quality gate status from SonarQube in Jenkins pipeline?

For the below pipeline script:对于以下管道脚本:

   stage('stage1'){

    withSonarQubeEnv(server){
            sh "${scannerHome}/bin/sonar-scanner"
        }
   }

stage1 launches Sonar scan and exit with success state. stage1启动声纳扫描并以成功状态退出。

stage2 waits for 30 minutes until sonar scan completes, jenkins is suppose to receive QualityGate status, as per below code. stage2等待 30 分钟,直到声纳扫描完成,jenkins 假设按照以下代码接收 QualityGate 状态。

   stage('stage2'){

        timeout(time: 40, unit: 'MINUTES') {
            def qGate = waitForQualityGate()
            if (qGate.status != 'OK') {
                error "Pipeline aborted due to quality gate failure: ${qGate.status}"
            }
        }
    }        

We have Sonar server and sonar scanner configured in Jenkins.我们在 Jenkins 中配置了声纳服务器和声纳扫描仪。

Is there additional configuration required to receive quality gate status?是否需要额外的配置来接收质量门状态?

To make it work you need:要使其工作,您需要:

  1. Sonarqube, use a recent version, LTS 6.7.x or 7.6 Sonarqube,使用最新版本,LTS 6.7.x 或 7.6
  2. the Sonarqube Jenkins plugin in version >= 2.6.1版本 >= 2.6.1 中的 Sonarqube Jenkins 插件
  3. the Sonarqube scanner configured in Jenkins在 Jenkins 中配置的 Sonarqube 扫描仪
  4. the Sonarqube host configured in Jenkins to make在 Jenkins 中配置的 Sonarqube 主机使
    withSonarQubeEnv(nameofyourconfiguredSonarHost) work withSonarQubeEnv(nameofyourconfiguredSonarHost)工作
  5. configure a webhook in Sonarqube server:在 Sonarqube 服务器中配置一个 webhook:
    goto https://yoursonarhost/admin/webhooks and use that URL转到https://yoursonarhost/admin/webhooks并使用该 URL
    https://yourjenkins/sonarqube-webhook/ https://yourjenkins/sonarqube-webhook/
    note the trailing '/' !注意尾随的 '/' !

After that it should work as expected.之后它应该按预期工作。 In my experience a timeout of 10 mins is sufficient.根据我的经验,10 分钟的超时就足够了。
Maybe there are additional settings needed, ie proxy or firewall to be able to access Jenkins from Sonarqube - it depends on your network.也许需要其他设置,即代理或防火墙才能从 Sonarqube 访问 Jenkins - 这取决于您的网络。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM