From 305c313da32436e2a2af2e2aa6430676a5427abf Mon Sep 17 00:00:00 2001 From: Sergey Kolekonov Date: Fri, 14 Feb 2014 12:13:39 +0400 Subject: [PATCH] Ruby metrics plugin support added Rcov plugin parses rcov html report files and shows it in Jenkins with a trend graph. Change-Id: I1f1d177c8681e68e5c12b520e263648842c701d0 --- jenkins_jobs/modules/publishers.py | 47 +++++++++++++++++++++ setup.py | 1 + tests/publishers/fixtures/ruby-metrics.xml | 22 ++++++++++ tests/publishers/fixtures/ruby-metrics.yaml | 12 ++++++ 4 files changed, 82 insertions(+) create mode 100644 tests/publishers/fixtures/ruby-metrics.xml create mode 100644 tests/publishers/fixtures/ruby-metrics.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c16d1c919..7361d2e9d 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -3355,6 +3355,53 @@ def artifact_deployer(parser, xml_parent, data): XML.SubElement(deployer, 'deployEvenBuildFail').text = deploy_if_fail +def ruby_metrics(parser, xml_parent, data): + """yaml: ruby-metrics + Rcov plugin parses rcov html report files and + shows it in Jenkins with a trend graph. + + Requires the Jenkins `Ruby metrics plugin. + `_ + + :arg str report-dir: Relative path to the coverage report directory + :arg dict targets: + + :targets: (total-coverage, code-coverage) + + * **healthy** (`int`): Healthy threshold + * **unhealthy** (`int`): Unhealthy threshold + * **unstable** (`int`): Unstable threshold + + Example: + + .. literalinclude:: /../../tests/publishers/fixtures/ruby-metrics.yaml + + """ + + metrics = XML.SubElement( + xml_parent, + 'hudson.plugins.rubyMetrics.rcov.RcovPublisher') + report_dir = data.get('report-dir', '') + XML.SubElement(metrics, 'reportDir').text = report_dir + targets = XML.SubElement(metrics, 'targets') + if 'target' in data: + for t in data['target']: + if not ('code-coverage' in t or 'total-coverage' in t): + raise JenkinsJobsException('Unrecognized target name') + el = XML.SubElement( + targets, + 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget') + if 'total-coverage' in t: + XML.SubElement(el, 'metric').text = 'TOTAL_COVERAGE' + else: + XML.SubElement(el, 'metric').text = 'CODE_COVERAGE' + for threshold_name, threshold_value in t.values()[0].items(): + elname = threshold_name.lower() + XML.SubElement(el, elname).text = str(threshold_value) + else: + raise JenkinsJobsException('Coverage metric targets must be set') + + class Publishers(jenkins_jobs.modules.base.Base): sequence = 70 diff --git a/setup.py b/setup.py index 52a1377f1..9e76f3bc6 100644 --- a/setup.py +++ b/setup.py @@ -169,6 +169,7 @@ setuptools.setup( 'plot=jenkins_jobs.modules.publishers:plot', 'post-tasks=jenkins_jobs.modules.publishers:post_tasks', 'robot=jenkins_jobs.modules.publishers:robot', + 'ruby-metrics=jenkins_jobs.modules.publishers:ruby_metrics', 'scp=jenkins_jobs.modules.publishers:scp', 'sloccount=jenkins_jobs.modules.publishers:sloccount', 'sonar=jenkins_jobs.modules.publishers:sonar', diff --git a/tests/publishers/fixtures/ruby-metrics.xml b/tests/publishers/fixtures/ruby-metrics.xml new file mode 100644 index 000000000..d0ecff407 --- /dev/null +++ b/tests/publishers/fixtures/ruby-metrics.xml @@ -0,0 +1,22 @@ + + + + + coverage/rcov + + + TOTAL_COVERAGE + 80 + 0 + 0 + + + CODE_COVERAGE + 80 + 0 + 0 + + + + + diff --git a/tests/publishers/fixtures/ruby-metrics.yaml b/tests/publishers/fixtures/ruby-metrics.yaml new file mode 100644 index 000000000..bb3bd884a --- /dev/null +++ b/tests/publishers/fixtures/ruby-metrics.yaml @@ -0,0 +1,12 @@ +publishers: + - ruby-metrics: + report-dir: "coverage/rcov" + target: + - total-coverage: + healthy: 80 + unhealthy: 0 + unstable: 0 + - code-coverage: + healthy: 80 + unhealthy: 0 + unstable: 0