我正在为 jenkins 使用管道插件,我想为每次运行生成代码覆盖率报告并将其与管道 ui 一起显示。有没有我可以使用的插件(例如 Cobertura,但它似乎不受管道支持)?
问问题
35117 次
4 回答
46
有一种方法可以添加管道步骤来发布您的覆盖率报告,但它不会显示在 BlueOcean 界面下。它会在正常的 UI 中正常显示。
pipeline {
agent any
stages {
...
}
post {
always {
junit '**/nosetests.xml'
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/coverage.xml', failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
}
}
}
请注意,Cobertura 插件的参数之一是它将使用的 XML(示例中为“**/coverage.xml”)。
如果您使用的是 python,您将需要使用以下内容:
nosetests --with-coverage --cover-xml --cover-package=pkg1,pkg2 --with-xunit test
于 2017-05-17T12:15:21.303 回答
44
现在您也可以cobertura
直接在 Jenkinsfile 中使用该命令
stage ("Extract test results") {
cobertura coberturaReportFile: 'path-to/coverage.xml'
}
于 2018-12-18T18:00:06.147 回答
7
hwjp 的答案是正确的,但是您可以将一些额外的参数添加到命令中,这些参数不容易找到。
安装 Cobertura 插件后,您可以在
作业仪表板页面 -> 管道语法 -> 步骤参考
还有一个片段生成器,它对入门非常有用
作业仪表板页面 -> 管道语法
示例命令:
cobertura coberturaReportFile: 'coverage.xml', enableNewApi: true, lineCoverageTargets: '80, 60, 70'
enableNewApi 是一个很好的设置为 true,因为新的 API 更漂亮:D 如果代码覆盖率太低,设置覆盖率目标将自动失败
于 2019-11-19T14:48:10.933 回答
-2
使用指定目录中的命令行 生成报告cobertura-report
并将结果作为工件附加。
cobertura-report [--datafile file] --destination dir [--format
html|xml] [--encoding encoding] directory [--basedir dir]
于 2017-02-27T15:25:02.383 回答