Fix workspace cleanup code

Ensure separate pattern tag is created for each pattern to be added.
This ensures that failure to add a pattern to the yaml will not trigger
an exception either.

Story: 2001109
Change-Id: I77f2b467e1f9b37817f5d516744abac8475a71ef
This commit is contained in:
Darragh Bailey 2017-07-07 17:57:10 +01:00
parent f05f2be5f2
commit 3e3002f351
5 changed files with 30 additions and 4 deletions

View File

@ -601,10 +601,16 @@ def workspace_cleanup(registry, xml_parent, data):
:arg str external-deletion-command: external deletion command to run
against files and directories
Example:
Full Example:
.. literalinclude::
/../../tests/wrappers/fixtures/workspace-cleanup001.yaml
/../../tests/wrappers/fixtures/workspace-cleanup-full.yaml
:language: yaml
Minimal Example:
.. literalinclude::
/../../tests/wrappers/fixtures/workspace-cleanup-min.yaml
:language: yaml
"""
@ -615,14 +621,15 @@ def workspace_cleanup(registry, xml_parent, data):
if "include" in data or "exclude" in data:
patterns = XML.SubElement(p, 'patterns')
ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
for inc in data.get("include", []):
ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
mapping = [
('', 'pattern', inc),
('', 'type', "INCLUDE")]
convert_mapping_to_xml(ptrn, data, mapping, fail_required=True)
for exc in data.get("exclude", []):
ptrn = XML.SubElement(patterns, 'hudson.plugins.ws__cleanup.Pattern')
mapping = [
('', 'pattern', exc),
('', 'type', "EXCLUDE")]

View File

@ -3,12 +3,16 @@
<buildWrappers>
<hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup">
<patterns>
<hudson.plugins.ws__cleanup.Pattern>
<pattern>_generated.py</pattern>
<type>INCLUDE</type>
</hudson.plugins.ws__cleanup.Pattern>
<hudson.plugins.ws__cleanup.Pattern>
<pattern>*.py</pattern>
<type>EXCLUDE</type>
</hudson.plugins.ws__cleanup.Pattern>
</patterns>
<deleteDirs>false</deleteDirs>
<deleteDirs>true</deleteDirs>
<cleanupParameter>DO_WS_CLEANUP</cleanupParameter>
<externalDelete>shred -u %s</externalDelete>
</hudson.plugins.ws__cleanup.PreBuildCleanup>

View File

@ -1,6 +1,9 @@
wrappers:
- workspace-cleanup:
include:
- "_generated.py"
exclude:
- "*.py"
dirmatch: true
check-parameter: "DO_WS_CLEANUP"
external-deletion-command: "shred -u %s"

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<buildWrappers>
<hudson.plugins.ws__cleanup.PreBuildCleanup plugin="ws-cleanup">
<deleteDirs>false</deleteDirs>
<cleanupParameter/>
<externalDelete/>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
</buildWrappers>
</project>

View File

@ -0,0 +1,2 @@
wrappers:
- workspace-cleanup