lunes, agosto 06, 2012

JaCoCo Jenkins Plugin


Hier soir deux inconnus, Et ce matin, sur l'avenue - Deux amoureux, tout etourdis , Par la longue nuit (Aux Champs Elysées - Joe Dassin)
In my post about JaCoCo I wrote about the problems of using JaCoCo Maven plugin in multimodule Maven project because of having one report for each module separately instead of one report for all modules, and how can be fixed it using JaCoCo Ant Task.

In current post we are going to see how to use Jacoco Jenkins plugin to achieve the same goal of Ant Task and have an overall code coverage statistic of all modules.

First step is installing JaCoCo Jenkins plugin.

Go to Go to Jenkins -> Manage Jenkins -> Plugin Manager -> Available and find for JaCoCo Plugin

Next step, if it is not done before, is configuring your JaCoCo Maven plugin into parent pom:


And finally a post-action must be configured to the job responsible of packaging the application. Note that in previous pom file reports are generated just before package goal is executed.

Go to Configure -> Post-build Actions -> Add post-build action -> Record JaCoCo coverage report.

Then we have to set folders or files containing JaCoCo XML reports, which using previous pom is **/target/site/jacoco/jacoco*.xml, and also set when we consider that a build is healthy in terms of coverage.


Then we can save the job configuration and run build project.

After project is build, a new report will appear just under test result trend graph, called code coverage trend, where we can see the code coverage of all project modules.


From left menu, you can enter to Coverage Report and watch code coverage of each module separately.


Furthermore visiting Jenkins main page a nice quick overview of a job when mouse is over the weather icon is shown:


Keep in mind that this approach for merging code coverage files will only work if you are using Jenkins as a CI system meanwhile Ant Task is more generic solution and can also be used with JaCoCo Jenkins plugin.

We Keep Learning,
Alex.

Music: http://www.youtube.com/watch?v=OAMuNfs89yE



5 comentarios:

ambro23 dijo...

I'd strongly suggest not to use jenkins to collect code coverage, checkstyle, etc. statistics by itself, rather set up Sonar and use the Sonar plugin for Jenkins to do all the code analyzing stuff. Sonar is more flexible: you don't need to modify (all!) your Jenkins jobs, once you add or change a metric. Furthermore Sonar has wider range and better representation of analysis results...

ambro23 dijo...
Este comentario ha sido eliminado por el autor.
Adrian Popiel dijo...

Hi, so I have a question. In my Jenkins v. 1.475 this Jacoco plugin looks poorer. It means I can only set Module name, jacoco.exec path and so on. Plugin in your screen looks like my emma plugin. I want my jacoco plugin looks and work like emma. Can you possibly help me?

Alex Soto dijo...

Hi Adrian, I am using Jenkins 1.474, it seems like Jenkins installation should not be the problem, have you installed JaCoCo plugin from Plugin Manager? Can you provide an screenshot to see exactly what happen?

Dominik Obermaier dijo...

Adrian,

this is because the Jenkins JoCoCo Plugin was rewritten in Version 1.0.3 to use the *.exec file instead of the generated xml files. You unfortunately have to download the jacoco jenkins source code and build the plugin yourself (https://github.com/jenkinsci/jacoco-plugin/archive/jacoco-1.0.2.zip). Then uninstall the jacoco plugin in jenkins and upload your new "old one". Let me know if that works for you, for me it did :)