https://wiki.jenkins-ci.org/display/JENKINS/GitHub+PR+Coverage+Status+Plugin
Parse code coverage report generated by build and post code coverage status comment to GitHub pull request:
- Jacoco
jacoco.xml
- Cobertura
cobertura.xml
orcobertura-coverage.xml
- Clover
clover.xml
- SimpleCov JSON (Ruby)
coverage.json
- Select or create new Jenkins build
- Ensure that build create code coverage report file
- Configure build to be triggered
- Or by Branch API Plugin
- Or by GitHub pull request builder plugin
- Install plugin from Jenkins Plugin Repository
- Or manually
- Configure global settings of plugin
- GitHub API URL keep blank for GitHub.com and fill if for dedicated instance of GitHub, example:
http(s)://hostname/api/v3/
- Set Personal Access Token (or keep blank if anonymous access enabled)
- GitHub API URL keep blank for GitHub.com and fill if for dedicated instance of GitHub, example:
- Setup Master Coverage (options)
- Add Record Master Coverage post build step to build which test your master
- Or goto
Manage Jenkins
and useUse Sonar for master coverage
- Add Publish coverage to GitHub post build step to build. It should be triggered by GitHub pull request builder plugin
- After running tests set build result to Success
- currentBuild.result = 'SUCCESS'
- Trigger MasterCoverageAction to collect master coverage
- step([$class: 'MasterCoverageAction'])
- Trigger CompareCoverageAction to compare coverage and publish results
- step([$class: 'CompareCoverageAction'])
You have the option to get the master coverage (base coverage) from your SonarQube instance. Otherwise the plugin will keep track of the master coverage in the project configuration file.
- Goto
Manage Jenkins
- Find section
Coverage status for GitHub Pull Requests
- Fill
Sonar URL
field - e.g.http://sonar.mycompany.com
- Turn On
Use Sonar for master coverage
- The next pullrequest build will use SonarQube as the the source for master coverage
The plugin will try to find the project in SonarQube based on the repository name. If more than one projects match, a waring is logged, and the first one will be used to get the coverage data.
This feature is still very basic. e.g. authorization against SonarQube is not yet implemented. Feel free to contribute.
Because of that GitHub can't render icon picture hosted on Jenkins. Plugin can use http://shields.io public resource instead of Jenkins hosted picture. To use it:
- Goto
Jenkins Configuration
- Turn on
Jenkins is not accessible for GitHub
- Done next coverage comment in Pull Request will use http://shields.io
If you see next picture on your pull request in GitHub:
In most cases that mean that your Jenkins runs on http
instead of https
Plugin uses same protocol as your Jenkins, however GitHub in most cases accessible by https
Default browser policy to block non secure resources on secure pages from unknown domain.
To fix that:
- Configure Jenkins to be accessible for
https
https://wiki.jenkins-ci.org/display/JENKINS/Starting+and+Accessing+Jenkins - Next you have a few options:
- Run your Jenkins on
https
only - Or configure plugin to publish link on picture over
https
- Open Jenkins
- Click
Manage Jenkins
- Click
Configure System
- Find section
Coverage status for GitHub Pull Requests
- Find property
Jenkins URL for icon in Pull Request
- Put URL to your Jenkins with
https
likehttps://jenkins.my.com
- Save
- Find section
- Restart Jenkins
- Support of https://github.com/jenkinsci/branch-api-plugin
- Support for Jenkins Pipeline
- Support single quotes for Cobertura Report
- Cobertura plugin ignores zero for
lineRate
orbranchRate
as resultlineRate=0 branchRate=0.5 => Coverage 25%
became0.5
aslineRate=0
, same policy forbranchRate
- Log Enchacements
Supporting Master Coverage from SonarQube. Check (details)[#master-coverage-from-sonar]
Supporting of private Jenkins with public GitHub. To enable that mode goto Jenkins Configuration and turn on Jenkins is not accessible for GitHub
Add support SimpleCov JSON coverage report for Ruby
Add alternative text to coverage image for case when GitHub doesn't able to show image
Correct parsing Cobertura report for edge cases
First public release to Jenkins Plugin Repo