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 @@ <?xml version="1.0" encoding="utf-8"?> <project> <publishers> - <hudson.plugins.ws__cleanup.WsCleanup plugin="ws-cleanup@0.14"> + <hudson.plugins.ws__cleanup.WsCleanup plugin="ws-cleanup"> <patterns> <hudson.plugins.ws__cleanup.Pattern> <pattern>*.zip</pattern> @@ -10,6 +10,7 @@ </patterns> <deleteDirs>false</deleteDirs> <cleanupMatrixParent>false</cleanupMatrixParent> + <externalDelete/> <cleanWhenSuccess>true</cleanWhenSuccess> <cleanWhenUnstable>true</cleanWhenUnstable> <cleanWhenFailure>true</cleanWhenFailure> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<project> + <buildWrappers> + <hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup"> + <patterns> + <hudson.plugins.ws__cleanup.Pattern> + <pattern>*.py</pattern> + <type>EXCLUDE</type> + </hudson.plugins.ws__cleanup.Pattern> + </patterns> + <deleteDirs>false</deleteDirs> + <cleanupParameter>DO_WS_CLEANUP</cleanupParameter> + <externalDelete>shred -u %s</externalDelete> + </hudson.plugins.ws__cleanup.PreBuildCleanup> + </buildWrappers> +</project> 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"