詹金斯声明性管道 - 覆盖率下降时构建失败

jenkins declerative pipeline - fail build when coverage drops

Jenkinsfile and publishing coverage report using cobertura 中使用 declerative 管道语法如下

cobertura(
  coberturaReportFile: 'coverage/cobertura-coverage.xml', 
  enableNewApi: true,
  autoUpdateHealth: true,
  autoUpdateStability: true,
  failUnstable: true,
  failUnhealthy: true,
  failNoReports: true,
  onlyStable: false
)

也尝试使用 code coverage api 如下:

publishCoverage(
  failUnhealthy: true, 
  calculateDiffForChangeRequests: true,
  failBuildIfCoverageDecreasedInChangeRequest: true,
  failNoReports: true,
  adapters: [
    coberturaAdapter(path: 'coverage/cobertura-coverage.xml')
  ]
)

查看我能找到的所有文档,如果不使用硬编码阈值,我无法弄清楚 what are the instructions to fail the build if coverage drops

希望能提供参考或代码片段。

autoUpdateHealth与硬编码阈值结合使用就可以了

cobertura(
  coberturaReportFile: 'coverage/cobertura-coverage.xml', 
  enableNewApi: true,
  autoUpdateHealth: true,
  autoUpdateStability: true,
  failUnstable: true,
  failUnhealthy: true,
  failNoReports: true,
  onlyStable: false
  conditionalCoverageTargets: '80, 0, 0',
  fileCoverageTargets: '80, 0, 0',
  lineCoverageTargets: '80, 0, 0',
  methodCoverageTargets: '80, 0, 0',
  packageCoverageTargets: '80, 0, 0',
)