Ramya AT
Ramya AT

Reputation: 159

How to specify Clover CoverageTarget Metrics in Jenkins Pipeline?

I'm using Clover plugin (https://wiki.jenkins-ci.org/display/JENKINS/Clover+Plugin) to publish my coverage metrics.

Also, I had configured "coverage target metrics" as shown herE:

enter image description here

Now that I've started to use Jenkins 2.0 Pipelines plugin, How can I specify these target metrics thro Groovy script (so that build fails if coverage is not met.)

Upvotes: 4

Views: 3581

Answers (3)

Marek
Marek

Reputation: 748

Example:

step([
  $class: 'CloverPublisher',
  cloverReportDir: 'target/site',
  cloverReportFileName: 'clover.xml',
  healthyTarget: [methodCoverage: 70, conditionalCoverage: 70, statementCoverage: 70], // optional, default is: method=70, conditional=80, statement=80
  unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 50, statementCoverage: 50], // optional, default is none
  failingTarget: [methodCoverage: 0, conditionalCoverage: 0, statementCoverage: 0]     // optional, default is none
])

Reference: https://wiki.jenkins-ci.org/display/JENKINS/Clover+Plugin

Upvotes: 3

Ramya AT
Ramya AT

Reputation: 159

So the solution i got working is:

in your package.json, define these tasks:

"test": "mocha test/  && npm run-script coverage",
"coverage": "npm run-script analyze-coverage && npm run-script check-coverage",
"analyze-coverage": "istanbul cover _mocha -- -R tap test/*.js  > test.tap && istanbul report clover",
"check-coverage": "istanbul check-coverage --lines 80"

Now npm test will fail if the code coverage (of lines) is less than 80% (see istanbul npm module for more options)

This actually removes the dependency of specifying the threshold in Clover Plugin and thus solves the issue.

Thanks Ramya

Upvotes: 0

whitediver
whitediver

Reputation: 468

I think your shoud use

step([$class: 'CloverPublisher', cloverReportDir: 'target/site/clover', cloverReportFileName: 'clover.xml'])

Upvotes: 2

Related Questions