4

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.)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ramya AT
  • 159
  • 3
  • 15

3 Answers3

3

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

Marek
  • 748
  • 6
  • 13
2

I think your shoud use

step([$class: 'CloverPublisher', cloverReportDir: 'target/site/clover', cloverReportFileName: 'clover.xml'])
whitediver
  • 462
  • 3
  • 12
0

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

Ramya AT
  • 159
  • 3
  • 15