summaryrefslogtreecommitdiffstats
path: root/jenkins_jobs/modules/publishers.py
diff options
context:
space:
mode:
authortanhengyeow <E0032242@u.nus.edu>2018-07-12 23:06:17 +0800
committertanhengyeow <E0032242@u.nus.edu>2018-07-13 22:56:12 +0800
commit9ab35beae88aa5031c629b1488d4a5d640a54448 (patch)
tree662a791567fa110cb01417ce2f659c479da8cce7 /jenkins_jobs/modules/publishers.py
parent746a089d4a699857ebd0dff5b5a0a6e51a7949f1 (diff)
downloadpython-jenkins-job-builder-9ab35beae88aa5031c629b1488d4a5d640a54448.tar.gz
python-jenkins-job-builder-9ab35beae88aa5031c629b1488d4a5d640a54448.tar.xz
python-jenkins-job-builder-9ab35beae88aa5031c629b1488d4a5d640a54448.zip
Refactor clone_workspace function to use convert_mapping_to_xml
1. Refactored the code in the function to utilize convert_mapping_to_xml's way of detecting valid types. 2. Refactored optional parameters to use convert_mapping_to_xml Note: This update will affect users using lowercase inputs in their YAML files. An exception will be raised if the inputs doesn't follow the exact casing required by the plugin. Change-Id: I053ef5f58200e51b3f6ff5ec55760f9e6f095370
Diffstat (limited to 'jenkins_jobs/modules/publishers.py')
-rw-r--r--jenkins_jobs/modules/publishers.py36
1 files changed, 10 insertions, 26 deletions
diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py
index e3d371a0..c8986bb9 100644
--- a/jenkins_jobs/modules/publishers.py
+++ b/jenkins_jobs/modules/publishers.py
@@ -638,39 +638,23 @@ def clone_workspace(registry, xml_parent, data):
'hudson.plugins.cloneworkspace.CloneWorkspacePublisher')
cloneworkspace.set('plugin', 'clone-workspace-scm')
+ criteria_valid_types = ['Any', 'Not Failed', 'Successful']
+ archive_valid_types = ['TAR', 'ZIP']
+
mappings = [
('workspace-glob', 'workspaceGlob', ''),
('override-default-excludes', 'overrideDefaultExcludes', False),
+ ('criteria', 'criteria', 'Any', criteria_valid_types),
+ ('archive-method', 'archiveMethod', 'TAR', archive_valid_types),
]
helpers.convert_mapping_to_xml(
cloneworkspace, data, mappings, fail_required=True)
- if 'workspace-exclude-glob' in data:
- XML.SubElement(
- cloneworkspace,
- 'workspaceExcludeGlob').text = data['workspace-exclude-glob']
-
- criteria_list = ['Any', 'Not Failed', 'Successful']
-
- criteria = data.get('criteria', 'Any').title()
-
- if 'criteria' in data and criteria not in criteria_list:
- raise JenkinsJobsException(
- 'clone-workspace criteria must be one of: ' +
- ', '.join(criteria_list))
- else:
- XML.SubElement(cloneworkspace, 'criteria').text = criteria
-
- archive_list = ['TAR', 'ZIP']
-
- archive_method = data.get('archive-method', 'TAR').upper()
-
- if 'archive-method' in data and archive_method not in archive_list:
- raise JenkinsJobsException(
- 'clone-workspace archive-method must be one of: ' +
- ', '.join(archive_list))
- else:
- XML.SubElement(cloneworkspace, 'archiveMethod').text = archive_method
+ mappings = [
+ ('workspace-exclude-glob', 'workspaceExcludeGlob', ''),
+ ]
+ helpers.convert_mapping_to_xml(
+ cloneworkspace, data, mappings, fail_required=False)
def cloud_foundry(parser, xml_parent, data):