From 13fa71cd822bfb047c07e0634e01149169e2aa91 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Mon, 25 Apr 2016 18:36:09 -0700 Subject: [PATCH] Update workspace-cleanup to support newer options This commit adds support for controlling whether cleanup runs via a job parameter and using an external deletion command. Change-Id: Ib80317c0e4cf95526ed59b719a1fd8df9c5e3f4f --- jenkins_jobs/modules/publishers.py | 6 +++++- jenkins_jobs/modules/wrappers.py | 19 ++++++++++++++----- .../fixtures/workspace-cleanup001.xml | 3 ++- .../fixtures/workspace-cleanup001.xml | 16 ++++++++++++++++ .../fixtures/workspace-cleanup001.yaml | 6 ++++++ 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 tests/wrappers/fixtures/workspace-cleanup001.xml create mode 100644 tests/wrappers/fixtures/workspace-cleanup001.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index e6738766e..197797c55 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2567,6 +2567,8 @@ def workspace_cleanup(parser, xml_parent, data): * **not-built** (`bool`) (default: true) :arg bool fail-build: Fail the build if the cleanup fails (default: true) :arg bool clean-parent: Cleanup matrix parent workspace (default: false) + :arg str external-deletion-command: external deletion command to run + against files and directories Example: @@ -2577,7 +2579,7 @@ def workspace_cleanup(parser, xml_parent, data): p = XML.SubElement(xml_parent, 'hudson.plugins.ws__cleanup.WsCleanup') - p.set("plugin", "ws-cleanup@0.14") + p.set("plugin", "ws-cleanup") if "include" in data or "exclude" in data: patterns = XML.SubElement(p, 'patterns') @@ -2595,6 +2597,8 @@ def workspace_cleanup(parser, xml_parent, data): 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', '')) mask = [('success', 'cleanWhenSuccess'), ('unstable', 'cleanWhenUnstable'), diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py index b05ebd8ae..489d24a38 100644 --- a/jenkins_jobs/modules/wrappers.py +++ b/jenkins_jobs/modules/wrappers.py @@ -571,18 +571,21 @@ def workspace_cleanup(parser, xml_parent, data): :arg list include: list of files to be included :arg list exclude: list of files to be excluded :arg bool dirmatch: Apply pattern to directories too (default: false) + :arg str check-parameter: boolean environment variable to check to + determine whether to actually clean up + :arg str external-deletion-command: external deletion command to run + against files and directories Example:: - wrappers: - - workspace-cleanup: - include: - - "*.zip" + .. literalinclude:: + /../../tests/wrappers/fixtures/workspace-cleanup001.yaml + :language: yaml """ p = XML.SubElement(xml_parent, 'hudson.plugins.ws__cleanup.PreBuildCleanup') - p.set("plugin", "ws-cleanup@0.14") + p.set("plugin", "ws-cleanup") if "include" in data or "exclude" in data: patterns = XML.SubElement(p, 'patterns') @@ -599,6 +602,12 @@ def workspace_cleanup(parser, xml_parent, data): deldirs = XML.SubElement(p, 'deleteDirs') deldirs.text = str(data.get("dirmatch", False)).lower() + XML.SubElement(p, 'cleanupParameter').text = str( + data.get('check-parameter', '')) + + XML.SubElement(p, 'externalDelete').text = str( + data.get('external-deletion-command', '')) + def m2_repository_cleanup(parser, xml_parent, data): """yaml: m2-repository-cleanup diff --git a/tests/publishers/fixtures/workspace-cleanup001.xml b/tests/publishers/fixtures/workspace-cleanup001.xml index dc6371567..192948746 100644 --- a/tests/publishers/fixtures/workspace-cleanup001.xml +++ b/tests/publishers/fixtures/workspace-cleanup001.xml @@ -1,7 +1,7 @@ - + *.zip @@ -10,6 +10,7 @@ false false + true true true diff --git a/tests/wrappers/fixtures/workspace-cleanup001.xml b/tests/wrappers/fixtures/workspace-cleanup001.xml new file mode 100644 index 000000000..f9e02c4c2 --- /dev/null +++ b/tests/wrappers/fixtures/workspace-cleanup001.xml @@ -0,0 +1,16 @@ + + + + + + + *.py + EXCLUDE + + + false + DO_WS_CLEANUP + shred -u %s + + + diff --git a/tests/wrappers/fixtures/workspace-cleanup001.yaml b/tests/wrappers/fixtures/workspace-cleanup001.yaml new file mode 100644 index 000000000..afb051438 --- /dev/null +++ b/tests/wrappers/fixtures/workspace-cleanup001.yaml @@ -0,0 +1,6 @@ +wrappers: + - workspace-cleanup: + exclude: + - "*.py" + check-parameter: "DO_WS_CLEANUP" + external-deletion-command: "shred -u %s"