From c8b360cb4772f9aeafad821b4f4448dba9e85822 Mon Sep 17 00:00:00 2001 From: Yolande Amate <yolandeamate@gmail.com> Date: Fri, 23 Jun 2017 16:53:34 +0100 Subject: [PATCH] Update archive to use convert_mapping_to_xml() Change-Id: Iaeabaeaa093335b57367b71d93bb17356bc59662 --- jenkins_jobs/modules/publishers.py | 47 +++++-------------- tests/publishers/fixtures/archive001.xml | 4 +- tests/publishers/fixtures/archive002.xml | 4 +- tests/publishers/fixtures/archive002.yaml | 1 + tests/publishers/fixtures/archive003.xml | 2 +- .../fixtures/conditional-publisher001.xml | 5 +- .../fixtures/conditional-publisher003.xml | 5 +- .../fixtures/conditional-publisher004.xml | 5 +- 8 files changed, 31 insertions(+), 42 deletions(-) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index b8a085d09..34484654a 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -63,44 +63,19 @@ def archive(registry, xml_parent, data): .. literalinclude:: /../../tests/publishers/fixtures/archive001.yaml :language: yaml """ - logger = logging.getLogger("%s:archive" % __name__) archiver = XML.SubElement(xml_parent, 'hudson.tasks.ArtifactArchiver') - artifacts = XML.SubElement(archiver, 'artifacts') - artifacts.text = data['artifacts'] + mapping = [ + ('artifacts', 'artifacts', None), + ('allow-empty', 'allowEmptyArchive', False), + ('only-if-success', 'onlyIfSuccessful', False), + ('fingerprint', 'fingerprint', False), + ('default-excludes', 'defaultExcludes', True), + ('case-sensitive', 'caseSensitive', True), + ('latest-only', 'latestOnly', False)] + if 'excludes' in data: - excludes = XML.SubElement(archiver, 'excludes') - excludes.text = data['excludes'] - latest = XML.SubElement(archiver, 'latestOnly') - # backward compatibility - latest_only = data.get('latest_only', False) - if 'latest_only' in data: - logger.warning('latest_only is deprecated please use latest-only') - if 'latest-only' in data: - latest_only = data['latest-only'] - if latest_only: - latest.text = 'true' - else: - latest.text = 'false' - - if 'allow-empty' in data: - empty = XML.SubElement(archiver, 'allowEmptyArchive') - # Default behavior is to fail the build. - empty.text = str(data.get('allow-empty', False)).lower() - - if 'only-if-success' in data: - success = XML.SubElement(archiver, 'onlyIfSuccessful') - success.text = str(data.get('only-if-success', False)).lower() - - if 'fingerprint' in data: - fingerprint = XML.SubElement(archiver, 'fingerprint') - fingerprint.text = str(data.get('fingerprint', False)).lower() - - default_excludes = XML.SubElement(archiver, 'defaultExcludes') - default_excludes.text = str(data.get('default-excludes', True)).lower() - - if 'case-sensitive' in data: - case_sensitive = XML.SubElement(archiver, 'caseSensitive') - case_sensitive.text = str(data.get('case-sensitive', True)).lower() + mapping.append(('excludes', 'excludes', None)) + helpers.convert_mapping_to_xml(archiver, data, mapping, fail_required=True) def blame_upstream(registry, xml_parent, data): diff --git a/tests/publishers/fixtures/archive001.xml b/tests/publishers/fixtures/archive001.xml index 7c49faefe..e95aac653 100644 --- a/tests/publishers/fixtures/archive001.xml +++ b/tests/publishers/fixtures/archive001.xml @@ -3,10 +3,12 @@ <publishers> <hudson.tasks.ArtifactArchiver> <artifacts>*.tar.gz</artifacts> - <latestOnly>false</latestOnly> <allowEmptyArchive>true</allowEmptyArchive> + <onlyIfSuccessful>false</onlyIfSuccessful> <fingerprint>true</fingerprint> <defaultExcludes>false</defaultExcludes> + <caseSensitive>true</caseSensitive> + <latestOnly>false</latestOnly> </hudson.tasks.ArtifactArchiver> </publishers> </project> diff --git a/tests/publishers/fixtures/archive002.xml b/tests/publishers/fixtures/archive002.xml index f06accfee..8d48f9460 100644 --- a/tests/publishers/fixtures/archive002.xml +++ b/tests/publishers/fixtures/archive002.xml @@ -3,11 +3,13 @@ <publishers> <hudson.tasks.ArtifactArchiver> <artifacts>*.tar.gz</artifacts> - <latestOnly>false</latestOnly> <allowEmptyArchive>true</allowEmptyArchive> <onlyIfSuccessful>true</onlyIfSuccessful> <fingerprint>true</fingerprint> <defaultExcludes>true</defaultExcludes> + <caseSensitive>true</caseSensitive> + <latestOnly>false</latestOnly> + <excludes>path</excludes> </hudson.tasks.ArtifactArchiver> </publishers> </project> diff --git a/tests/publishers/fixtures/archive002.yaml b/tests/publishers/fixtures/archive002.yaml index e14fd20c7..b91526b38 100644 --- a/tests/publishers/fixtures/archive002.yaml +++ b/tests/publishers/fixtures/archive002.yaml @@ -4,3 +4,4 @@ publishers: allow-empty: true only-if-success: true fingerprint: true + excludes: path diff --git a/tests/publishers/fixtures/archive003.xml b/tests/publishers/fixtures/archive003.xml index 4ce5ff6e9..0b9747362 100644 --- a/tests/publishers/fixtures/archive003.xml +++ b/tests/publishers/fixtures/archive003.xml @@ -3,12 +3,12 @@ <publishers> <hudson.tasks.ArtifactArchiver> <artifacts>*.tar.gz</artifacts> - <latestOnly>false</latestOnly> <allowEmptyArchive>true</allowEmptyArchive> <onlyIfSuccessful>false</onlyIfSuccessful> <fingerprint>true</fingerprint> <defaultExcludes>true</defaultExcludes> <caseSensitive>false</caseSensitive> + <latestOnly>false</latestOnly> </hudson.tasks.ArtifactArchiver> </publishers> </project> diff --git a/tests/publishers/fixtures/conditional-publisher001.xml b/tests/publishers/fixtures/conditional-publisher001.xml index 99b324350..f0b1a224b 100644 --- a/tests/publishers/fixtures/conditional-publisher001.xml +++ b/tests/publishers/fixtures/conditional-publisher001.xml @@ -21,9 +21,12 @@ <runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail"/> <publisher class="hudson.tasks.ArtifactArchiver"> <artifacts>**/**</artifacts> - <latestOnly>false</latestOnly> <allowEmptyArchive>true</allowEmptyArchive> + <onlyIfSuccessful>false</onlyIfSuccessful> + <fingerprint>false</fingerprint> <defaultExcludes>true</defaultExcludes> + <caseSensitive>true</caseSensitive> + <latestOnly>false</latestOnly> </publisher> </org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher> </publishers> diff --git a/tests/publishers/fixtures/conditional-publisher003.xml b/tests/publishers/fixtures/conditional-publisher003.xml index 46197b9e2..8da31ea8a 100644 --- a/tests/publishers/fixtures/conditional-publisher003.xml +++ b/tests/publishers/fixtures/conditional-publisher003.xml @@ -9,9 +9,12 @@ <publisherList> <hudson.tasks.ArtifactArchiver> <artifacts>**/**</artifacts> - <latestOnly>false</latestOnly> <allowEmptyArchive>true</allowEmptyArchive> + <onlyIfSuccessful>false</onlyIfSuccessful> + <fingerprint>false</fingerprint> <defaultExcludes>true</defaultExcludes> + <caseSensitive>true</caseSensitive> + <latestOnly>false</latestOnly> </hudson.tasks.ArtifactArchiver> <hudson.tasks.test.AggregatedTestResultPublisher> <includeFailedBuilds>true</includeFailedBuilds> diff --git a/tests/publishers/fixtures/conditional-publisher004.xml b/tests/publishers/fixtures/conditional-publisher004.xml index fec92f7dd..91a2e633b 100644 --- a/tests/publishers/fixtures/conditional-publisher004.xml +++ b/tests/publishers/fixtures/conditional-publisher004.xml @@ -11,9 +11,12 @@ <runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail"/> <publisher class="hudson.tasks.ArtifactArchiver"> <artifacts>**/**</artifacts> - <latestOnly>false</latestOnly> <allowEmptyArchive>true</allowEmptyArchive> + <onlyIfSuccessful>false</onlyIfSuccessful> + <fingerprint>false</fingerprint> <defaultExcludes>true</defaultExcludes> + <caseSensitive>true</caseSensitive> + <latestOnly>false</latestOnly> </publisher> </org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher> </publishers>