English 中文(简体)
如何配置 Jenkins Cobertura 插件来监视特定软件包?
原标题:How to configure Jenkins Cobertura plugin to monitor specific packages?

我的项目有许多包件 (“ 模型 ”, “ 控制者 ” 等 ) 。 我用 Cobertura 插件设置了 Jenkins 来生成覆盖报告, 这很棒 。 如果覆盖低于一定的阈值, 但只针对某些包件( 比如“ 控制者 ”, 但不包括“ 模型 ” ), 我想将一个建筑标为不稳定 。 在配置 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:])
问题回答

暂无回答




相关问题
Reuse agent without needing to declare it multiple times

I m trying to define a agent in a jenkinsfile once, but use it in multiple stages without needing to fully declare it for each stage. As can be seen, I am using a stage to figure out which docker ...

在Jenkins Templating引擎实施版本

我们正计划利用JTE(Jenkins Templating的发动机)在我们org建造管道。 有许多管道将使用这一模板。 可能的话,模板的任何改动都会中断......

Hudson gitorious plugin?

Has anyone integrated a local copy of gitorious with Hudson? Specifically, linking the sha1 on Hudson web page back to the gitorious web page.

Problem with Hudson-JIRA-Perforce integration

I m looking at using the Hudson JIRA plugin to post a JIRA comment on each build. The SCM I m using is perforce which is already linked to the JIRA tasks using perforce jobs. I can see that the JIRA ...

Two Hudson Masters on the same Windows Server

I want to setup two Hudson Masters on the same Hardware. This will make administering Hudson easier, since both servers are used by two different (and independent) teams. So far I tried to install ...

Using Hudson and build steps with multiple git repositories

I m trying out Hudson to replace our current Buildbot setup. I installed the git plugin. Our current setup is like: ssh://server:/repo/test_framework.git ssh://server:/repo/project_a.git Now, to ...

热门标签