gpt4 book ai didi

jenkins - 如何配置 Jenkins Cobertura 插件来监控特定包?

转载 作者:行者123 更新时间:2023-12-02 21:02:34 25 4
gpt4 key购买 nike

我的项目有许多包(“模型”、“ Controller ”等)。我已经使用 Cobertura 插件设置了 Jenkins 来生成覆盖率报告,这非常棒。如果覆盖率低于某个阈值,我想将构建标记为不稳定,但仅限于某些包(例如“ Controller ”,但不是“模型”)。然而,我在配置 UI 中没有看到明显的方法来执行此操作 - 看起来阈值是全局的。

有办法做到这一点吗?

最佳答案

(在这里回答我自己的问题)

据我所知,这是不可能的——经过几天的观察,我还没有看到任何东西。我编写了一个简单的脚本,可以执行我想要的操作 - 获取覆盖率输出,对其进行解析,如果特定包的覆盖率未达到特定阈值,则构建失败。它很脏,可以清理/扩展,但基本思想就在这里。欢迎评论。

#!/usr/bin/env python

'''
Jenkins' Cobertura plugin doesn't allow marking a build as successful or
failed based on coverage of individual packages -- only the project as a
whole. This script will parse the coverage.xml file and fail if the coverage of
specified packages doesn't meet the thresholds given

'''

import sys

from lxml import etree

PACKAGES_XPATH = etree.XPath('/coverage/packages/package')


def main(argv):
filename = argv[0]
package_args = argv[1:] if len(argv) > 1 else []
# format is package_name:coverage_threshold
package_coverage = {package: int(coverage) for
package, coverage in [x.split(':') for x in package_args]}

xml = open(filename, 'r').read()
root = etree.fromstring(xml)

packages = PACKAGES_XPATH(root)

failed = False
for package in packages:
name = package.get('name')
if name in package_coverage:
# We care about this one
print 'Checking package {} -- need {}% coverage'.format(
name, package_coverage[name])
coverage = float(package.get('line-rate', '0.0')) * 100
if coverage < package_coverage[name]:
print ('FAILED - Coverage for package {} is {}% -- '
'minimum is {}%'.format(
name, coverage, package_coverage[name]))
failed = True
else:
print "PASS"

if failed:
sys.exit(1)

if __name__ == '__main__':
main(sys.argv[1:])

关于jenkins - 如何配置 Jenkins Cobertura 插件来监控特定包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10747514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com