Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cobertura code coverage report for jenkins pipeline jobs

I'm using the pipeline plugin for jenkins and I'd like to generate code coverage report for each run and display it along with the pipeline ui. Is there a plugin I can use to do that(e.g. Cobertura but it doesn't seem to be supported by pipeline)?

like image 417
ebnius Avatar asked Apr 28 '16 14:04

ebnius


People also ask

How do I generate a coverage report in cobertura?

start test in web interface ( by default localhost:9000/@tests) and go to your_host:your_port/@cobertura ( by default it's http://localhost:9000/@cobertura ) for generate new report or reset previous. And now you can see html report in iframe or directly on file:/path/to/your/application/test-result/code-coverage/.


2 Answers

There is a way to add a pipeline step to publish your coverage report but it doesn't show under the BlueOcean interface. It will show fine in the normal UI.

pipeline {     agent any      stages {         ...     }     post {         always {             junit '**/nosetests.xml'             step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/coverage.xml', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])         }     } } 

Note that one of the parameters to the Cobertura plugin is the XML that it will use ('**/coverage.xml' in the example).

If you are using python, you will want to use something like:

nosetests --with-coverage --cover-xml --cover-package=pkg1,pkg2 --with-xunit test 
like image 100
Roman Kutlak Avatar answered Sep 19 '22 07:09

Roman Kutlak


Nowadays you can also use the cobertura command directly in a Jenkinsfile

stage ("Extract test results") {     cobertura coberturaReportFile: 'path-to/coverage.xml' } 

source: https://issues.jenkins-ci.org/browse/JENKINS-30700

like image 33
hwjp Avatar answered Sep 23 '22 07:09

hwjp