Sonarqube 质量门不向 jenkins 发送 webhook [英] Sonarqube quality gate not sending webhook to jenkins

查看:94
本文介绍了Sonarqube 质量门不向 jenkins 发送 webhook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Jenkins 配置为使用 sonarqube 扫描仪.扫描工作正常.詹金斯管道正在工作,詹金斯日志中没有任何问题.

I configure Jenkins to work with sonarqube scanner. The scan are working fine. The jenkins pipeline is working and I don't have any isssue in the jenkins log.

SonarQube 扫描仪 3.0.3.778詹金斯:2.70SonarQube Scanner for Jenkins 插件:2.6.1

SonarQube Scanner 3.0.3.778 Jenkins: 2.70 SonarQube Scanner for Jenkins plugin: 2.6.1

我使用这个代码:

    stage('SonarQube analysis') {
        sh 'sed -ie "s|_PROJECT_|${PROJECT_CODE}|g" $WORKSPACE/_pipeline/sonar-project.properties'
        // requires SonarQube Scanner 3.0+
        def scannerHome = '/opt/sonar/bin/sonar-scanner';
        withSonarQubeEnv('mscodeanalysis') {
            sh "${scannerHome}/bin/sonar-scanner -Dproject.settings=$WORKSPACE/_pipeline/sonar-project.properties"
        }
    }
    }
    }
}
    }
    // No need to occupy a node
    stage("Quality Gate"){
        timeout(time: 15, unit: 'MINUTES') { // Just in case something goes wrong, pipeline will be killed after a timeout
        def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
            if (qg.status != 'OK') {
                error "Pipeline aborted due to quality gate failure: ${qg.status}"
            }
        }
    }

我的问题来自质量门.它从不将 json 有效负载发布到詹金斯.我在 jenkins 日志中没有看到 json 条目.但我知道 jenkins 和 sonarqube 服务器之间的连接正在工作,因为我能够使用 curl 从 sonarqube VM 发送 POST.

My problem come from Quality Gate. It never POST the json payload to jenkins. I don't see a json entry inside jenkins log. But I know the connection between jenkins and sonarqube server is working because I was able to send a POST using curl from the sonarqube VM.

这里是詹金斯的工作输出:

Here the jenkins job output:

Timeout set to expire in 15 min
[Pipeline] {
[Pipeline] waitForQualityGate
Checking status of SonarQube task 'AV3irVJXpvBxXXNJYZkd' on server 'mscodeanalysis'
SonarQube task 'AV3irVJXpvBxXXNJYZkd' status is 'PENDING'
Cancelling nested steps due to timeout

这是我从未到达 jenkins 管道的有效负载:网址:http://sonar-server:9000/api/ce/task?id=AV3irVJXpvBxXXNJYZkd

Here is my payload that never reach jenkins pipeline: url: http://sonar-server:9000/api/ce/task?id=AV3irVJXpvBxXXNJYZkd

{"task":{"organization":"default-organization","id":"AV3irVJXpvBxXXNJYZkd","type":"REPORT","componentId":"AV3hrJeCfL_nrF2072FH","componentKey":"POOL-003","componentName":"POOL-003","componentQualifier":"TRK","analysisId":"AV3irVkZszLEB6PsCK9X","status":"SUCCESS","submittedAt":"2017-08-14T21:36:35+0000","submitterLogin":"jenkins","startedAt":"2017-08-14T21:36:37+0000","executedAt":"2017-08-14T21:36:38+0000","executionTimeMs":650,"logs":false,"hasScannerContext":true}}

我无法插入图像,但质量门为通过,分析任务成功.

I can't insert image but the Quality gate is Pass and the analysis task is success.

如果我需要提供更多信息,请告诉我.谢谢

Let me know if I need to include more information. Thank you

推荐答案

问题可能是 Jenkins 使用带有自签名证书的 https.那么解决方案是:

The issue could be that Jenkins is using https with self-signed certificate. Then solution is:

  1. 为 SonarQube 生成信任库:

  1. Generate truststore for SonarQube:

keytool -import -trustcacerts -alias jenkins-host-name -file cert.crt -keystore sonarqube.jks

密钥库密码:密码

其中 cert.crt - 是 jenkins 用于 ssl 的证书,jenkins-host-name - 是 docker 网络中 jenkins 的主机名(在 webhook 中使用)

Where cert.crt - is certificate used for ssl for jenkins, jenkins-host-name - is a hostname of jenkins in the docker network (which is used in webhook)

将信任库添加到 SonarQube Dockerfile:

Add truststore to SonarQube Dockerfile:

FROM sonarqube
COPY sonarqube.jks /var/sonar_cert/
COPY sonar.properties /opt/sonarqube/conf/sonar.properties

  • 更新 sonar.properties

  • Update sonar.properties

    sonar.ce.javaAdditionalOpts=-Djavax.net.ssl.trustStore=/var/sonar_cert/sonarqube.jks -Djavax.net.ssl.trustStorePassword=password
    

  • 如果您在 webhook URL 中提供了正确的 Jenkins 用户名和密码,那么一切都应该正常工作.

    Then if you have a correct user and password for Jenkins provided in webhook URL everything should work.

    已尝试:Jenkins 2.107.2、SonarQube 7.1

    Tried: Jenkins 2.107.2, SonarQube 7.1

    这篇关于Sonarqube 质量门不向 jenkins 发送 webhook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆