Jenkins 2 - Sonar 6.3 - 未找到JaCoCo报告

时间:2017-05-19 12:11:05

标签: maven jenkins sonarqube jacoco sonarqube-scan

我正在尝试将cobertura报告纳入SonarQube 6.1。我已经按照这个文档:

https://docs.sonarqube.org/display/PLUG/Code+Coverage+by+Unit+Tests+for+Java+Project https://docs.sonarqube.org/display/PLUG/Usage+of+JaCoCo+with+Java+Plugin

总而言之,我已将Jenkins管道配置为运行以下Maven语句:

sh "${mvnHome}/bin/mvn clean verify org.jacoco:jacoco-maven-plugin:prepare-agent org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar -Dmaven.test.failure.ignore=true -Dsonar.jacoco.reportPaths=${env.WORKSPACE}/target/jacoco.exec"

构建日志显示已生成JaCoCo报告:

[INFO] argLine set to -javaagent:/var/jenkins_home/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/var/jenkins_home/workspace/MY_PROJECT/target/jacoco.exec

但是当它试图访问它时,它无法找到它:

[INFO] Sensor JaCoCoSensor [java]
[INFO] JaCoCo report not found: '/var/jenkins_home/workspace/MY_PROJECT/target/jacoco.exec'

我已经验证在我的笔记本电脑上运行此语句的/target/jacoco.exe中正确生成了该文件:

mvn org.jacoco:jacoco-maven-plugin:prepare-agent -Dmaven.test.failure.ignore=true clean verify 

为什么它不起作用?

1 个答案:

答案 0 :(得分:1)

解决!问题在于操作的顺序。重新排序后,找到jacoco.exec文件并将覆盖信息传输到声纳:

sh "${mvnHome}/bin/mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar -Dmaven.test.failure.ignore=true -Dsonar.jacoco.reportPaths=${env.WORKSPACE}/target/jacoco.exec"