如何在Jenkins管道中指定Clover CoverageTarget度量标准?

时间:2016-05-26 07:25:53

标签: jenkins jenkins-pipeline clover

我使用Clover插件(https://wiki.jenkins-ci.org/display/JENKINS/Clover+Plugin)发布我的覆盖率指标。

另外,我已经配置了"覆盖目标指标"如图所示:

enter image description here

现在我已经开始使用Jenkins 2.0 Pipelines插件了,如何在Groovy脚本中指定这些目标指标(如果不满足覆盖范围,则构建失败。)

3 个答案:

答案 0 :(得分:2)

我认为你应该使用

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

答案 1 :(得分:1)

示例:

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

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

答案 2 :(得分:0)

所以我开始工作的解决方案是:

在package.json中

,定义以下任务:

"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"

如果代码覆盖率(行数)小于80%,则npm test将失败(有关更多选项,请参阅istanbul npm模块)

这实际上消除了在Clover插件中指定阈值的依赖性,从而解决了问题。

由于 拉姆亚