版本:SonarQube:7.9 SonarJava 插件:5.13.1 Java:11 Gradle:5.5我正在嘗試使用聲明性 Jenkins 管道對 Gitlab Repo 和 Gradle/Java 項目進行 SonarQube 分析。這是詹金斯文件:@Library('jenkins-shared')_pipeline { agent { docker { image 'gradle:5.5-jdk11' } } stages { stage('build && SonarQube analysis') { steps { withSonarQubeEnv('sonar.tools.****) { script { cmd.withNexusCredentials { sh 'gradle --info sonarqube -Dsonar.projectKey=catalog-service -Dsonar.junit.reportPaths=./build/test-results/test -Dsonar.binaries=./build/classes -Dsonar.coverage.jacoco.xmlReportPaths=./build/reports/jacoco/test/html/index.html' } } } } } stage("Quality Gate") { steps { timeout(time: 1, unit: 'HOURS') { // Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails // true = set pipeline to UNSTABLE, false = don't // Requires SonarScanner for Jenkins 2.7+ waitForQualityGate abortPipeline: true } } } }}我也將 Sonar 插件應用于 Gradle 構建文件。當我嘗試運行此 Jenkins 管道時,出現以下錯誤:> Task :sonarqube FAILEDJaCoCo report task detected, but XML report is not enabled or it was not produced. Coverage for this task will not be reported.Caching disabled for task ':sonarqube' because: Build cache is disabledTask ':sonarqube' is not up-to-date because: Task has not declared any outputs despite executing actions.JaCoCo report task detected, but XML report is not enabled or it was not produced. Coverage for this task will not be reported.User cache: ?/.sonar/cache:sonarqube (Thread[Execution worker for ':',5,main]) completed. Took 0.221 secs.其他所有任務都成功完成。即使當我運行 jacocoTestConverageVerification 或檢查時,它總是成功運行,除了任務 Sonarqube
1 回答

揚帆大魚
TA貢獻1799條經驗 獲得超9個贊
已解決:創建聲納分析所需的臨時文件的用戶授權存在問題,因此您需要使用 Jenkins 的適當用戶運行分析。例如,只需嘗試使用 root 用戶運行它。
此外,SonarQube 需要生成 XML 報告文件,這些文件默認處于關閉狀態。您可以像這樣在 build.gradle 中打開 XML 文件的生成:
jacocoTestReport {
reports {
xml.enabled true
}
}
添加回答
舉報
0/150
提交
取消