From 897b825900e52e50a5679671cc3f0aa5f1c36451 Mon Sep 17 00:00:00 2001 From: Dong Ma Date: Sat, 24 Jun 2017 16:07:28 +0800 Subject: [PATCH] Update build_publisher plugin - update build_publisher to use convert xml - update test cases - remove the tailing \ Change-Id: I5b63ff85108725878f48e0562e49bb3129ab8935 --- jenkins_jobs/modules/publishers.py | 39 ++++++++++++------- ...lisher002.xml => build-publisher-full.xml} | 4 +- ...sher002.yaml => build-publisher-full.yaml} | 4 +- ...her001.xml => build-publisher-minimal.xml} | 0 .../fixtures/build-publisher-minimal.yaml | 2 + .../fixtures/build-publisher001.yaml | 4 -- 6 files changed, 30 insertions(+), 23 deletions(-) rename tests/publishers/fixtures/{build-publisher002.xml => build-publisher-full.xml} (78%) rename tests/publishers/fixtures/{build-publisher002.yaml => build-publisher-full.yaml} (52%) rename tests/publishers/fixtures/{build-publisher001.xml => build-publisher-minimal.xml} (100%) create mode 100644 tests/publishers/fixtures/build-publisher-minimal.yaml delete mode 100644 tests/publishers/fixtures/build-publisher001.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index b8a085d09..fa4f7ff13 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -4372,10 +4372,16 @@ def build_publisher(registry, xml_parent, data): :arg int num-to-keep: number of jobs to keep in the published results (optional) - Example: + Minimal Example: .. literalinclude:: - /../../tests/publishers/fixtures/build-publisher002.yaml + /../../tests/publishers/fixtures/build-publisher-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/build-publisher-full.yaml :language: yaml """ @@ -4383,21 +4389,24 @@ def build_publisher(registry, xml_parent, data): xml_parent, 'hudson.plugins.build__publisher.BuildPublisher') - 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() - + mappings = [ + ('publish-unstable-builds', 'publishUnstableBuilds', True), + ('publish-failed-builds', 'publishFailedBuilds', True) + ] + helpers.convert_mapping_to_xml( + reporter, data, mappings, fail_required=True) if 'days-to-keep' in data or 'num-to-keep' in data: 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)) - # hardcoded to -1 to emulate what the build publisher - # plugin seem to do. - XML.SubElement(logrotator, 'artifactDaysToKeep').text = "-1" - XML.SubElement(logrotator, 'artifactNumToKeep').text = "-1" + mappings = [ + ('days-to-keep', 'daysToKeep', -1), + ('num-to-keep', 'numToKeep', -1), + # hardcoded to -1 to emulate what the build publisher + # plugin seem to do. + ('', 'artifactDaysToKeep', -1), + ('', 'artifactNumToKeep', -1) + ] + helpers.convert_mapping_to_xml( + logrotator, data, mappings, fail_required=True) def stash(registry, xml_parent, data): diff --git a/tests/publishers/fixtures/build-publisher002.xml b/tests/publishers/fixtures/build-publisher-full.xml similarity index 78% rename from tests/publishers/fixtures/build-publisher002.xml rename to tests/publishers/fixtures/build-publisher-full.xml index 301324f0b..1afec5a68 100644 --- a/tests/publishers/fixtures/build-publisher002.xml +++ b/tests/publishers/fixtures/build-publisher-full.xml @@ -2,8 +2,8 @@ - true - true + false + false -1 100 diff --git a/tests/publishers/fixtures/build-publisher002.yaml b/tests/publishers/fixtures/build-publisher-full.yaml similarity index 52% rename from tests/publishers/fixtures/build-publisher002.yaml rename to tests/publishers/fixtures/build-publisher-full.yaml index d7ef6132c..e7570cbfb 100644 --- a/tests/publishers/fixtures/build-publisher002.yaml +++ b/tests/publishers/fixtures/build-publisher-full.yaml @@ -1,6 +1,6 @@ publishers: - build-publisher: - publish-unstable-builds: true - publish-failed-builds: true + publish-unstable-builds: false + publish-failed-builds: false days-to-keep: -1 num-to-keep: 100 diff --git a/tests/publishers/fixtures/build-publisher001.xml b/tests/publishers/fixtures/build-publisher-minimal.xml similarity index 100% rename from tests/publishers/fixtures/build-publisher001.xml rename to tests/publishers/fixtures/build-publisher-minimal.xml diff --git a/tests/publishers/fixtures/build-publisher-minimal.yaml b/tests/publishers/fixtures/build-publisher-minimal.yaml new file mode 100644 index 000000000..7072a7546 --- /dev/null +++ b/tests/publishers/fixtures/build-publisher-minimal.yaml @@ -0,0 +1,2 @@ +publishers: + - build-publisher diff --git a/tests/publishers/fixtures/build-publisher001.yaml b/tests/publishers/fixtures/build-publisher001.yaml deleted file mode 100644 index 0d3a58628..000000000 --- a/tests/publishers/fixtures/build-publisher001.yaml +++ /dev/null @@ -1,4 +0,0 @@ -publishers: - - build-publisher: - publish-unstable-builds: true - publish-failed-builds: true