“Project coverage set to 0%” - JaCoCo and Sonar in Jenkins with Ant

I transferred my work from one Hudson machine to Wednesday with several Jenkins subordinates, and now JaCoCo coverage no longer works.

JOB (old): Hudson 2.0.1, Jenkins Sonar Plugin 1.7.1, Sonar 2.1.2

BROKEN (new): Jenkins 1.446, Jenkins Sonar Plugin 1.7.2, Sonar 2.1.2

My Hudson job is called Pinnacle, and it was used to run on the same Hudson server with Sonar on the same machine. I created my (NO MAVEN) build by doing the following.

1) Added Ant target in my build.xml called test-with-coverage

2) Configured the Pinnacle job in Hudson to "invoke standalone sonar analysis" with these properties:

 sonar.projectKey=com.skyboximaging:pinnacle sonar.projectName="Pinnacle" sonar.projectVersion=1.0 sources=Pinnacle/src/java tests=Pinnacle/test/java binaries=Pinnacle/classes sonar.jacoco.reportPath=Pinnacle/jacoco.exec sonar.jacoco.antTargets=test-with-coverage 

(Note that the code is uploaded to the Pinnacle directory in the Jenkins workspace.)

3) Configured “general settings” sonar to use JaCoCo to cover code

Everything worked beautifully!

But in the new Jenkins environment, I see this error in the output of the Jenkins assembly:

 23:15:17.863 INFO Sensor JaCoCoSensor... 23:15:17.868 INFO Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/workspace/Pinnacle/Pinnacle/jacoco.exec 

This file does not exist on the slave where the assembly was performed. (The directory / var / lib / jenkins / workspace / Pinnacle / Pinnacle exists.)

All other sensors (FindBugs, PMD, etc.) work fine. Just JaCoCo is broken.

Does Sonar / JaCoCo support multiple Jenkins subordinate environments?

I suspect the Ant test-with-coverage task is not starting. How does Sonar find build.xml? And what is different from the old and new installation?

+7
source share
1 answer

I recently installed and successfully launched Sonar and Jacoco. Since I recently with this topic, I decided that I would check on stackoverflow for similar problems and would help. I get results from Jacoco, but found that you need to explicitly specify the following parameters in addition to the properties specified in your post:

 sonar.core.codeCoveragePlugin=jacoco sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec sonar.dynamicAnalysis=reuseReports sonar.surefire.reportsPath=tests/test-reports 

You need to set sonar.core.codeCoveragePlugin = jacoco if you want to use the sonar.jacoco.reportPath property. Otherwise, you will have to use the sonar.jacoco.itReportPath property. However, I recommend just setting the codeCoveragePlugin and reportPath properties. Otherwise, it will not be displayed under the default coverage widget in the sonar. Please note: you cannot use the default coverage tool and jacoco together. It must be this or that. I decided to use Jacoco.

Your ant target must be configured to generate jacoco.exec results before running sonar tasks:

 <jacoco:coverage enabled="${tests.code.coverage}" destfile="${jacoco.exec.dest}"> <junit fork="yes" printsummary="withOutAndErr" dir="${tests.working.dir}"> ... 

Be sure to tell the sonar to reuse reports and any sun reports if you use junit in front of the sonar, that is, if you use junit outside the sonar:

 sonar.dynamicAnalysis=reuseReports sonar.jacoco.reportPath=tests/jacoco-exec/jacoco.exec sonar.surefire.reportsPath=tests/test-reports 

For some reason, if you need more detailed debugging, use the following property:

sonar.verbose = true

+9
source

All Articles