我将 Jenkins 配置为与 sonarqube 扫描仪一起使用。扫描工作正常。詹金斯管道正在工作,詹金斯日志中没有任何问题。
SonarQube 扫描仪 3.0.3.778
詹金斯:2.70
适用于 Jenkins 的 SonarQube 扫描仪插件: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 有效负载 POST 到 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
这是我从未到达詹金斯管道的有效负载:
网址:http://sonar-server:9000/api/ce/task?id=AV3irVJXpvBxXXNJYZkd 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}}
我无法插入图像,但质量门已通过并且分析任务成功。
如果我需要提供更多信息,请告诉我。
谢谢