Enhance support for the Cobertura Coverage Plugin. Deprecates the coverage module.

Increases the amount of recognizable parameters, modularizes existing parameters
and maintains default values.

Modularizes the construction of coverage reports. Coverage reports can now be fully
specified within JJB YAML. Coverage reports now use a default value of zero for
healthy, unhealthy, and unstable. Additionally, at least one target must be specified.

Coverage module gets a documentation and logger warning against its use. Logger object
moved to the head of the code.

Change-Id: I505a6185b3f9005fbbd9786ebdca0ef02ed618f0
Reviewed-on: https://review.openstack.org/28184
Reviewed-by: James E. Blair <corvus@inaugust.com>
Approved: Clark Boylan <clark.boylan@gmail.com>
Reviewed-by: Clark Boylan <clark.boylan@gmail.com>
Tested-by: Jenkins
This commit is contained in:
Eric Erfanian
2013-05-03 12:24:12 -05:00
committed by Jenkins
parent 73540705e1
commit d753ed3ec0
2 changed files with 118 additions and 1 deletions

View File

@@ -189,7 +189,8 @@ def trigger(parser, xml_parent, data):
def coverage(parser, xml_parent, data):
"""yaml: coverage
Generate a cobertura coverage report.
WARNING: The coverage function is deprecated. Instead, use the
cobertura function to generate a cobertura coverage report.
Requires the Jenkins `Cobertura Coverage Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin>`_
@@ -198,6 +199,9 @@ def coverage(parser, xml_parent, data):
publishers:
- coverage
"""
logger = logging.getLogger(__name__)
logger.warn("Coverage function is deprecated. Switch to cobertura.")
cobertura = XML.SubElement(xml_parent,
'hudson.plugins.cobertura.CoberturaPublisher')
XML.SubElement(cobertura, 'coberturaReportFile').text = '**/coverage.xml'
@@ -253,6 +257,118 @@ def coverage(parser, xml_parent, data):
XML.SubElement(cobertura, 'sourceEncoding').text = 'ASCII'
def cobertura(parser, xml_parent, data):
"""yaml: cobertura
Generate a cobertura coverage report.
Requires the Jenkins `Cobertura Coverage Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin>`_
:arg str report-file: This is a file name pattern that can be used
to locate the cobertura xml report files (optional)
:arg bool only-stable: Include only stable builds (default false)
:arg bool fail-no-reports: fail builds if no coverage reports are found
(default false)
:arg bool fail-unhealthy: Unhealthy projects will be failed
(default false)
:arg bool fail-unstable: Unstable projects will be failed (default false)
:arg bool health-auto-update: Auto update threshold for health on
successful build (default false)
:arg bool stability-auto-update: Auto update threshold for stability on
successful build (default false)
:arg bool zoom-coverage-chart: Zoom the coverage chart and crop area below
the minimum and above the maximum coverage
of the past reports (default false)
:arg str source-encoding: Override the source encoding (default ASCII)
:arg dict targets:
:targets: (packages, files, classes, method, line, conditional)
* **healthy** (`int`): Healthy threshold (default 0)
* **unhealthy** (`int`): Unhealthy threshold (default 0)
* **failing** (`int`): Failing threshold (default 0)
Example::
publishers:
- cobertura:
report-file: "/reports/cobertura/coverage.xml"
only-stable: "true"
fail-no-reports: "true"
fail-unhealthy: "true"
fail-unstable: "true"
health-auto-update: "true"
stability-auto-update: "true"
zoom-coverage-chart: "true"
source-encoding: "Big5"
targets:
- files:
healthy: 10
unhealthy: 20
failing: 30
- method:
healthy: 50
unhealthy: 40
failing: 30
"""
cobertura = XML.SubElement(xml_parent,
'hudson.plugins.cobertura.CoberturaPublisher')
XML.SubElement(cobertura, 'coberturaReportFile').text = data.get(
'report-file', '**/coverage.xml')
XML.SubElement(cobertura, 'onlyStable').text = str(
data.get('only-stable', 'false')).lower()
XML.SubElement(cobertura, 'failUnhealthy').text = str(
data.get('fail-unhealthy', 'false')).lower()
XML.SubElement(cobertura, 'failUnstable').text = str(
data.get('fail-unstable', 'false')).lower()
XML.SubElement(cobertura, 'autoUpdateHealth').text = str(
data.get('health-auto-update', 'false')).lower()
XML.SubElement(cobertura, 'autoUpdateStability').text = str(
data.get('stability-auto-update', 'false')).lower()
XML.SubElement(cobertura, 'zoomCoverageChart').text = str(
data.get('zoom-coverage-chart', 'false')).lower()
XML.SubElement(cobertura, 'failNoReports').text = str(
data.get('fail-no-reports', 'false')).lower()
healthy = XML.SubElement(cobertura, 'healthyTarget')
targets = XML.SubElement(healthy, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
for item in data['targets']:
item_name = item.keys()[0]
item_values = item.get(item_name, 0)
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry,
'hudson.plugins.cobertura.targets.'
'CoverageMetric').text = str(item_name).upper()
XML.SubElement(entry, 'int').text = str(item_values.get('healthy', 0))
unhealthy = XML.SubElement(cobertura, 'unhealthyTarget')
targets = XML.SubElement(unhealthy, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
for item in data['targets']:
item_name = item.keys()[0]
item_values = item.get(item_name, 0)
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
'CoverageMetric').text = str(item_name).upper()
XML.SubElement(entry, 'int').text = str(item_values.get('unhealthy',
0))
failing = XML.SubElement(cobertura, 'failingTarget')
targets = XML.SubElement(failing, 'targets', {
'class': 'enum-map',
'enum-type': 'hudson.plugins.cobertura.targets.CoverageMetric'})
for item in data['targets']:
item_name = item.keys()[0]
item_values = item.get(item_name, 0)
entry = XML.SubElement(targets, 'entry')
XML.SubElement(entry, 'hudson.plugins.cobertura.targets.'
'CoverageMetric').text = str(item_name).upper()
XML.SubElement(entry, 'int').text = str(item_values.get('failing', 0))
XML.SubElement(cobertura, 'sourceEncoding').text = data.get(
'source-encoding', 'ASCII')
def ftp(parser, xml_parent, data):
"""yaml: ftp
Upload files via FTP.

View File

@@ -105,6 +105,7 @@ setuptools.setup(
'jenkins_jobs.modules.publishers:trigger_parameterized_builds',
'trigger=jenkins_jobs.modules.publishers:trigger',
'coverage=jenkins_jobs.modules.publishers:coverage',
'cobertura=jenkins_jobs.modules.publishers:cobertura',
'ftp=jenkins_jobs.modules.publishers:ftp',
'junit=jenkins_jobs.modules.publishers:junit',
'xunit=jenkins_jobs.modules.publishers:xunit',