4

Jacoco plugin showing 0% coverage in jenkins reports but when I ran the same command in local system, jacoco generates reports properly. I'm using following command:

mvn -s xyz/settings.xml -f xyz/xyz/pom.xml clean install org.jacoco:jacoco-maven-plugin:report-aggregate

So When I run this command in jenkins it generates wrong reports. I've checed it in WorkSpace directory for corresponding project in jenkins. It shows 0% coverage for every project. But when I run the same maven command in my local system jacoco-maven generates correct coverage reports. I can see them in as they are in HTML format.

My pom.xml has this to run jacoco with maven:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.7.201606060606</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I'm using following tools:

jacoco-maven-plugin version 0.7.7
jenkins-jacoco-plugin version 2.0.1
apache-maven version 3.5.0

Also this is my jenkins console log which I'm getting after the maven command is finished.

[JaCoCo plugin] Collecting JaCoCo coverage data...
[JaCoCo plugin] **/**.exec;**/target/classes;**/src; locations are configured
[JaCoCo plugin] Number of found exec files for pattern **/**.exec: 0
[JaCoCo plugin] Saving matched execfiles:  
[JaCoCo plugin] Saving matched class directories for class-pattern: **/target/classes:
<<<<<<Classes folders list for all project>>>>>>>>
[JaCoCo plugin] Loading inclusions files..
[JaCoCo plugin] inclusions: []
[JaCoCo plugin] exclusions: []
[JaCoCo plugin] Thresholds: JacocoHealthReportThresholds [minClass=0, maxClass=0, minMethod=0, maxMethod=0, minLine=0, maxLine=0, minBranch=0, maxBranch=0, minInstruction=0, maxInstruction=0, minComplexity=0, maxComplexity=0]
[JaCoCo plugin] Publishing the results..
[JaCoCo plugin] Loading packages..
[JaCoCo plugin] Done.
[JaCoCo plugin] Overall coverage: class: 0, method: 0, line: 0, branch: 0, instruction: 0
Finished: SUCCESS

Below is my jenkins setup for jacoco reports:

enter image description here

And here is my folder structure of target directory.

enter image description here

target directory is present under project dir.

So my real concern is why on jenkins these files ie coverage files are not getting generated correctly while same command in my local system generates correct coverage report.

Thanks.

P.S. :- I'm doing this in multimodule environment where my source files are present in one project and test files are available in another project. So for every source project there exist a test project. Also one thing I just noticed that after running maven command, Class files are getting created under /target/classes directory of source while html files for the reports are getting generated under /target/site directory of test project. I'm not sure why this is.

Jay
  • 1,257
  • 2
  • 11
  • 16
  • Line `Number of found exec files for pattern **/**.exec: 0` in log is suspicious - wild guess, but can you try something like `**/*.exec` or `**/jacoco.exec` ? – Godin Sep 23 '17 at 23:20
  • Yes I'll try that. But files are not getting generated properly in jenkins system itself. So even if it takes exec file using correct path it won't show correct report bcz the report itself is getting generated wrong in jenkins box. – Jay Sep 25 '17 at 06:51
  • Please also re-read documentation http://www.jacoco.org/jacoco/trunk/doc/report-mojo.html and http://www.jacoco.org/jacoco/trunk/doc/report-aggregate-mojo.html about locations of generated files and etc. Strange that you mix them and that you request execution of last one from command line, because it takes into account dependencies of module where executed and only those that are part of reactor, i.e. that are part of current build. – Godin Sep 25 '17 at 11:50
  • "the report itself is getting generated wrong in jenkins" - absolutely unclear which one - report that is generated by Jenkins plugin, or the report generated by jacoco-maven-plugin? Focus on one problem at a time instead of mixing everything. If second one is correct, then problem is in Jenkins plugin configuration. If second one is incorrect, then this has nothing to do with Jenkins plugin configuration. – Godin Sep 25 '17 at 11:57
  • 1
    Jacoco-maven-plugin when ran in local system it's generating proper and correct reports. But in jenkins system the reports generated using same command is not correct. In jenkins we can check workspace directory for checking files generated in target directory of each project. There I found jacoco reports with wrong stats ie 0 coverage. – Jay Sep 26 '17 at 08:46

1 Answers1

2

I found the piece of code I missed because of which the reports were not generating in jenkins.

I forgot to add jacoco-maven-plugin inside <reporting> tag of parent pom.xml. I had only added it inside <pluginManagement> & <build>.

:-)

Ruslan López
  • 4,433
  • 2
  • 26
  • 37
Jay
  • 1,257
  • 2
  • 11
  • 16