From 8bfa671220ffd1a5a8f493f8c6ac278a825bf3c0 Mon Sep 17 00:00:00 2001 From: Yolanda Robla Date: Thu, 14 Nov 2013 11:35:11 +0100 Subject: [PATCH] Add build-publisher to jenkins-job-builder Added new build-publisher following guidelines: https://wiki.jenkins-ci.org/display/JENKINS/Build+Publisher+Plugin Add to the list of publishers, implement module, provide tests Change-Id: I7c130f4375cffc2a5e9acea6b417edc3e12886e7 Closes-Bug: #1234959 --- jenkins_jobs/modules/publishers.py | 46 +++++++++++++++++++++++++ setup.py | 1 + tests/publishers/fixtures/build001.xml | 16 +++++++++ tests/publishers/fixtures/build001.yaml | 10 ++++++ 4 files changed, 73 insertions(+) create mode 100644 tests/publishers/fixtures/build001.xml create mode 100644 tests/publishers/fixtures/build001.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 71135a1b2..b95a4129a 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2810,6 +2810,52 @@ def git(parser, xml_parent, data): handle_entity_children(note['note'], xml_note, note_mappings) +def build_publisher(parser, xml_parent, data): + """yaml: build-publisher + This plugin allows records from one Jenkins to be published + on another Jenkins. + + Requires the Jenkins `Build Publisher Plugin. + `_ + + :arg str servers: Specify the servers where to publish + + + Example:: + + publishers: + - build-publisher: + name: servername + publish-unstable-builds: true + publish-failed-builds: true + days-to-keep: -1 + num-to-keep: -1 + artifact-days-to-keep: -1 + artifact-num-to-keep: -1 + + """ + + reporter = XML.SubElement( + xml_parent, + 'hudson.plugins.build__publisher.BuildPublisher') + + XML.SubElement(reporter, 'serverName').text = data['name'] + XML.SubElement(reporter, 'publishUnstableBuilds').text = \ + str(data.get('publish-unstable-builds', True)).lower() + XML.SubElement(reporter, 'publishFailedBuilds').text = \ + str(data.get('publish-failed-builds', True)).lower() + + logrotator = XML.SubElement(reporter, 'logRotator') + XML.SubElement(logrotator, 'daysToKeep').text = \ + str(data.get('days-to-keep', -1)) + XML.SubElement(logrotator, 'numToKeep').text = \ + str(data.get('num-to-keep', -1)) + XML.SubElement(logrotator, 'artifactDaysToKeep').text = \ + str(data.get('artifact-days-to-keep', -1)) + XML.SubElement(logrotator, 'artifactNumToKeep').text = \ + str(data.get('artifact-num-to-keep', -1)) + + class Publishers(jenkins_jobs.modules.base.Base): sequence = 70 diff --git a/setup.py b/setup.py index 78209a16b..1b78498d1 100644 --- a/setup.py +++ b/setup.py @@ -120,6 +120,7 @@ setuptools.setup( 'jenkins_jobs.publishers': [ 'aggregate-tests=jenkins_jobs.modules.publishers:aggregate_tests', 'archive=jenkins_jobs.modules.publishers:archive', + 'build-publisher=jenkins_jobs.modules.publishers:build_publisher', 'checkstyle=jenkins_jobs.modules.publishers:checkstyle', 'cifs=jenkins_jobs.modules.publishers:cifs', 'claim-build=jenkins_jobs.modules.publishers:claim_build', diff --git a/tests/publishers/fixtures/build001.xml b/tests/publishers/fixtures/build001.xml new file mode 100644 index 000000000..60ada7f59 --- /dev/null +++ b/tests/publishers/fixtures/build001.xml @@ -0,0 +1,16 @@ + + + + + servername + true + false + + -1 + 100 + -1 + 100 + + + + diff --git a/tests/publishers/fixtures/build001.yaml b/tests/publishers/fixtures/build001.yaml new file mode 100644 index 000000000..40bbc5750 --- /dev/null +++ b/tests/publishers/fixtures/build001.yaml @@ -0,0 +1,10 @@ +# vim: sw=4 ts=4 et +publishers: + - build-publisher: + name: servername + publish-unstable-builds: true + publish-failed-builds: false + days-to-keep: -1 + num-to-keep: 100 + artifact-days-to-keep: -1 + artifact-num-to-keep: 100