How to get coverage percentage in jenkins pipeline

Viewed 378

I am using cobertura to publish coverage report from xml file in the post section of a stage. I would like to also get the coverage percentage and send it in a mail inside post section.

stage (publish){
steps{
       ......
}
post {
            success {
               publishCoverage adapters: [coberturaAdapter(path: 'coverage-dir/coverage.xml',
               thresholds: [[failUnhealthy: true, thresholdTarget: 'Line', unhealthyThreshold: 90.0]])],
               failNoReports: true, failUnhealthy: true,
               globalThresholds: [[failUnhealthy: true, thresholdTarget: 'Aggregated Report', unhealthyThreshold: 90.0]],
               sourceFileResolver: sourceFiles('NEVER_STORE')
            }
}
}

post {

      success {
         mail to:"...",
         subject:"SUCCESS",
         body: "Coverage percentage of test is ${Percentage}"
      }

      failure {
         mail to:"...",
         subject:"SUCCESS",
         body: "Coverage percentage of test is ${Percentage}"

      }
}

I would want to add something in post section after publishing report that fetches the coverage percentage and stores in a variable. Is it possible to do that?

0 Answers
Related