Sonarqube质量门未将Webhook发送给詹金斯 [英] Sonarqube quality gate not sending webhook to jenkins

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

问题描述

我将Jenkins配置为与声纳扫描仪一起使用.扫描工作正常. jenkins管道正在运行,并且在jenkins日志中没有任何问题.

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.70 用于Jenkins插件的SonarQube Scanner: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.我在jenkins日志中没有看到json条目.但是我知道jenkins和sonarqube服务器之间的连接正在工作,因为我能够使用sonarqube VM的curl发送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.

    尝试:詹金斯2.107.2,SonarQube 7.1

    Tried: Jenkins 2.107.2, SonarQube 7.1

    这篇关于Sonarqube质量门未将Webhook发送给詹金斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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