This plugin serves as API to integrate and publish multiple coverage report types. More information see https://jenkins.io/projects/gsoc/2018/code-coverage-api-plugin/.
- Pipeline support
- Modernized coverage chart
- Coverage trend
- Source code navigation
- Parallel execution in pipeline support
- Reports combining
- REST API
- Failed conditions and flexible threshold setting
- Other small features
See the CHANGELOG.
see wiki.
Config maven to generate Cobertura coverage reports:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>xml</format>
</formats>
<check/>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
More information about Cobertura.
Config maven to generate JaCoCo coverage reports:
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
More Information about JaCoCo.
Use llvm-cov to generate JSON format report:
$ llvm-cov export -instr-profile /path/to/foo.profdata /path/to/foo
More Information llvm-cov.
2. Install Jenkins plugins which implement Code Coverage API plugin (cobertura-plugin, llvm-cov-plugin).
We also support pipeline configuration, you can generate pipeline code in Jenkins Snippet Generator.
publishCoverage adapters: [jacocoAdapter('target/site/jacoco/jacoco.xml')]
You can also use jacoco
instead of jacocoAdapter
if you didn't install Jacoco-Plugin.
We support parallel pipeline. You can call the Code Coverage API plugin in different branches like this:
node {
parallel firstBranch: {
publishCoverage adapters: [jacocoAdapter('target/site/jacoco/jacoco.xml')]
}, secondBranch: {
publishCoverage adapters: [jacocoAdapter('jacoco.xml')]
}
}
You can add tag on publishCoverage and Code Coverage API plugin will combine reports have same tag:
node {
parallel firstBranch: {
publishCoverage adapters: [jacocoAdapter('target/site/jacoco/jacoco.xml')], tag: ‘t’
}, secondBranch: {
publishCoverage adapters: [jacocoAdapter('jacoco.xml')], tag: ‘t’
}
}
There is also a possibility to merge multiple reports (e.g. from multiple xml files) into one using the mergeToOneReport
option with an ant-style path pattern.
All reports found by the adapter will then be combined into a single report:
publishCoverage adapters: [jacocoAdapter(mergeToOneReport: true, path: '**/*.xml')]
We provide a REST API to retrieve coverage data:
- Coverage result:
…/{buildNumber}/coverage/…/result/api/\{json|xml\}?depth={number}
- Trend result:
…/{buildNumber}/coverage/…/trend/api/\{json|xml\}?depth={number}
- Coverage result of last build:
…/{buildNumber}/coverage/…/last/result/api/\{json|xml\}?depth={number}
- Trend result of last build:
…/{buildNumber}/coverage/…/last/trend/api/\{json|xml\}?depth={number}
Note: The larger the number, the deeper of coverage information can be retrieved.