Reputation: 41
I have the following challenge which I would like to resolve. Here's a current setup:
So currently in Jenkins we have 2 builds, one for normal delivery and another one to produce sonar reports.
What we would like to do would be to have a build generated with the JaCoCo argument line and ship this one to our QA team in order to get better coverage numbers which we could append or merge with the numbers generated by the sonar build we make every day. The build sent to QA would be installed onto a different server than the one we are generating the build from.
What would be the best approach to perform this. Eventually we would like to also get JaCoCo reports from our dev workstations and append those numbers to our sonar page.
EDIT 1
Thank to details provided on this thread I was able to startup my multi-module application with the following JVM option : "-javaagent:${MAIN_DIR}/lib/jacocoagent.jar==destfile=/jacoco.exec,output=tcpserver,address=*"
In my Jenkins build I have Pre Steps going as follow : An ant task that calls target jacocoReport. The build.xml I'm using for this purpose has the following code;
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="/opt/hudson/tools/jacocoant.jar"/>
</taskdef>
<target name="jacocoReport">
<jacoco:dump address="${jacoco.host}" port="${jacoco.port}" dump="true" reset="true" destfile="${jacocoReportFile}" append="false"/>
</target>
<target name="jacocoReset">
<jacoco:dump address="${jacoco.host}" port="${jacoco.port}" reset="true" destfile="${jacocoReportFile}" append="false"/>
<delete file="${jacocoReportFile}"/>
</target>
And finally I have a maven build step which calls sonar:sonar
Here's the section in the POM relative to my integration report;
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.itReportPath>${WORKSPACE}/it-jacoco.exec</sonar.jacoco.itReportPath>
<sonar.language>java</sonar.language>
<sonar.branch>9.9.5</sonar.branch>
When the build finishes, my Sonar entry still shows at 0% for my integration tests. But when I take the same it-jacoco.exec report and import it using Eclipse's Jacoco import Coverage session, I get 26% coverage.
Finally when I look into my Jenkins build logs I see the following;
Sensor JaCoCoItSensor...
Analysing /var/lib/jenkins/workspace/XXXXXX/it-jacoco.exec
No information about coverage per test.
Sensor JaCoCoItSensor done: 34 ms
Upvotes: 1
Views: 4551
Reputation: 775
Gathering coverage from any application instance is easily achievable due to jacoco on-the-fly instrumentation feature. You only have to provide jacocoagent.jar and add following option to JVM call:
-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]
Here is more detailed documentation on this:
http://www.eclemma.org/jacoco/trunk/doc/agent.html
Next, during Maven Sonar build execution you shall provide following parameter with path to generated coverage file:
-Dsonar.jacoco.itReportPath=<path>
You can find here detailed description:
http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Integration+Tests+for+Java+Project
Upvotes: 1