Sonarqube质量门未将Webhook发送给詹金斯

Mar*_*arc 5 jenkins sonarqube quality-gate

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

SonarQube Scanner 3.0.3.778 Jenkins:2.70 SonarQube Scanner for Jenkins插件: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}"
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

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

这是詹金斯工作的输出:

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
Run Code Online (Sandbox Code Playgroud)

这是我永远无法到达詹金斯管道的有效载荷:网址: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}}
Run Code Online (Sandbox Code Playgroud)

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

让我知道是否需要提供更多信息。谢谢

Mar*_*arc -1

在 stage('SonarQube Analysis') 和 stage(“Quality Gate”) 之间添加 sh 'sleep 10' 可以解决此问题。现在詹金斯工作收到

Checking status of SonarQube task 'AV3rHxhp3io6giaQF_OA' on server 'sonarserver'
SonarQube task 'AV3rHxhp3io6giaQF_OA' status is 'SUCCESS'
SonarQube task 'AV3rHxhp3io6giaQF_OA' completed. Quality gate is 'OK'
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,这并不能证明问题已得到解决。这可能只是SonarQube端的异步任务需要不到10秒才能完成。因此,您收到“成功”不是因为 Webhook,而是因为 waitForQualityGate 启动时任务已完成。 (2认同)
  • 抱歉,这不是解决方案。这种“解决方法”的结果是,该工作将冻结!我从https://github.com/jenkinsci/sonarqube-plugin/blob/master/src/main/java/org/sonarsource/scanner/jenkins/pipeline/WaitForQualityGateStep.java学习了源代码。有两步。(1)尝试通过sonar/api/ce/task?id=xxxxx直接调用sonar qube。(2) 如果结果不成功,那么他们将创建包含侦听器 SonarQubeWebHook 的异步任务。但问题仍然是,那个声纳没有呼叫詹金斯! (2认同)