From 5a9f6b17871ff30ee40df5dde3d51b5fc7e34e1a Mon Sep 17 00:00:00 2001 From: Dong Ma <winterma.dong@gmail.com> Date: Thu, 1 Dec 2016 01:13:02 -0800 Subject: [PATCH] Update workspace-cleanup plugin - update workspace-cleanup plugin to convert xml - remove trailing \ - update test cases Change-Id: I7e5a126d7610811ac8c1120d01292f1c28f82f82 --- jenkins_jobs/modules/publishers.py | 22 ++++++++++------ .../fixtures/workspace-cleanup-complete.xml | 26 +++++++++++++++++++ .../fixtures/workspace-cleanup-complete.yaml | 16 ++++++++++++ ...p001.xml => workspace-cleanup-minimal.xml} | 8 +----- .../fixtures/workspace-cleanup-minimal.yaml | 2 ++ .../fixtures/workspace-cleanup001.yaml | 7 ----- 6 files changed, 59 insertions(+), 22 deletions(-) create mode 100644 tests/publishers/fixtures/workspace-cleanup-complete.xml create mode 100644 tests/publishers/fixtures/workspace-cleanup-complete.yaml rename tests/publishers/fixtures/{workspace-cleanup001.xml => workspace-cleanup-minimal.xml} (69%) create mode 100644 tests/publishers/fixtures/workspace-cleanup-minimal.yaml delete mode 100644 tests/publishers/fixtures/workspace-cleanup001.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index fef4ec275..04d591cdb 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2926,10 +2926,16 @@ def workspace_cleanup(registry, xml_parent, data): :arg str external-deletion-command: external deletion command to run against files and directories - Example: + Minimal Example: .. literalinclude:: - /../../tests/publishers/fixtures/workspace-cleanup001.yaml + /../../tests/publishers/fixtures/workspace-cleanup-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/publishers/fixtures/workspace-cleanup-complete.yaml :language: yaml """ @@ -2949,12 +2955,12 @@ def workspace_cleanup(registry, xml_parent, data): XML.SubElement(ptrn, 'pattern').text = exc XML.SubElement(ptrn, 'type').text = "EXCLUDE" - XML.SubElement(p, 'deleteDirs').text = \ - str(data.get("dirmatch", False)).lower() - XML.SubElement(p, 'cleanupMatrixParent').text = \ - str(data.get("clean-parent", False)).lower() - XML.SubElement(p, 'externalDelete').text = \ - str(data.get('external-deletion-command', '')) + mappings = [ + ('dirmatch', 'deleteDirs', False), + ('clean-parent', 'cleanupMatrixParent', False), + ('external-deletion-command', 'externalDelete', '') + ] + helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True) mask = [('success', 'cleanWhenSuccess'), ('unstable', 'cleanWhenUnstable'), diff --git a/tests/publishers/fixtures/workspace-cleanup-complete.xml b/tests/publishers/fixtures/workspace-cleanup-complete.xml new file mode 100644 index 000000000..d55638632 --- /dev/null +++ b/tests/publishers/fixtures/workspace-cleanup-complete.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<project> + <publishers> + <hudson.plugins.ws__cleanup.WsCleanup plugin="ws-cleanup"> + <patterns> + <hudson.plugins.ws__cleanup.Pattern> + <pattern>*.zip</pattern> + <type>INCLUDE</type> + </hudson.plugins.ws__cleanup.Pattern> + <hudson.plugins.ws__cleanup.Pattern> + <pattern>*.txt</pattern> + <type>EXCLUDE</type> + </hudson.plugins.ws__cleanup.Pattern> + </patterns> + <deleteDirs>true</deleteDirs> + <cleanupMatrixParent>true</cleanupMatrixParent> + <externalDelete>command</externalDelete> + <cleanWhenSuccess>false</cleanWhenSuccess> + <cleanWhenUnstable>false</cleanWhenUnstable> + <cleanWhenFailure>false</cleanWhenFailure> + <cleanWhenNotBuilt>false</cleanWhenNotBuilt> + <cleanWhenAborted>false</cleanWhenAborted> + <notFailBuild>true</notFailBuild> + </hudson.plugins.ws__cleanup.WsCleanup> + </publishers> +</project> diff --git a/tests/publishers/fixtures/workspace-cleanup-complete.yaml b/tests/publishers/fixtures/workspace-cleanup-complete.yaml new file mode 100644 index 000000000..1ea41495b --- /dev/null +++ b/tests/publishers/fixtures/workspace-cleanup-complete.yaml @@ -0,0 +1,16 @@ +publishers: + - workspace-cleanup: + include: + - "*.zip" + exclude: + - "*.txt" + clean-if: + - success: false + - unstable: false + - failure: false + - aborted: false + - not-built: false + dirmatch: true + fail-build: false + clean-parent: true + external-deletion-command: 'command' diff --git a/tests/publishers/fixtures/workspace-cleanup001.xml b/tests/publishers/fixtures/workspace-cleanup-minimal.xml similarity index 69% rename from tests/publishers/fixtures/workspace-cleanup001.xml rename to tests/publishers/fixtures/workspace-cleanup-minimal.xml index 192948746..36f0e03ef 100644 --- a/tests/publishers/fixtures/workspace-cleanup001.xml +++ b/tests/publishers/fixtures/workspace-cleanup-minimal.xml @@ -2,19 +2,13 @@ <project> <publishers> <hudson.plugins.ws__cleanup.WsCleanup plugin="ws-cleanup"> - <patterns> - <hudson.plugins.ws__cleanup.Pattern> - <pattern>*.zip</pattern> - <type>INCLUDE</type> - </hudson.plugins.ws__cleanup.Pattern> - </patterns> <deleteDirs>false</deleteDirs> <cleanupMatrixParent>false</cleanupMatrixParent> <externalDelete/> <cleanWhenSuccess>true</cleanWhenSuccess> <cleanWhenUnstable>true</cleanWhenUnstable> <cleanWhenFailure>true</cleanWhenFailure> - <cleanWhenNotBuilt>false</cleanWhenNotBuilt> + <cleanWhenNotBuilt>true</cleanWhenNotBuilt> <cleanWhenAborted>true</cleanWhenAborted> <notFailBuild>true</notFailBuild> </hudson.plugins.ws__cleanup.WsCleanup> diff --git a/tests/publishers/fixtures/workspace-cleanup-minimal.yaml b/tests/publishers/fixtures/workspace-cleanup-minimal.yaml new file mode 100644 index 000000000..aa91ee6b2 --- /dev/null +++ b/tests/publishers/fixtures/workspace-cleanup-minimal.yaml @@ -0,0 +1,2 @@ +publishers: + - workspace-cleanup diff --git a/tests/publishers/fixtures/workspace-cleanup001.yaml b/tests/publishers/fixtures/workspace-cleanup001.yaml deleted file mode 100644 index 79caf3b73..000000000 --- a/tests/publishers/fixtures/workspace-cleanup001.yaml +++ /dev/null @@ -1,7 +0,0 @@ -publishers: - - workspace-cleanup: - include: - - "*.zip" - clean-if: - - success: true - - not-built: false