summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortanhengyeow <E0032242@u.nus.edu>2018-07-08 19:42:19 +0800
committertanhengyeow <E0032242@u.nus.edu>2018-07-08 22:47:35 +0800
commitf7d5ef5617729ec54c54cb5de3af477d6b8236cf (patch)
tree8b89d56d3c545d25237a9c8672e9f9314766ba22
parent11941c87f448ce525eec9a8ca77c00c2b119eee7 (diff)
Refactor ivy function in triggers.py to utilize convert_mapping_to_xml
Refactor the code in the function to utilize convert_mapping_to_xml. Change-Id: Ic62b5cc60d260f9f4820c4260f69771e1f8589ba
Notes
Notes (review): Code-Review+2: Kien Ha <kienha9922@gmail.com> Code-Review+1: Anil Belur <askb23@gmail.com> Code-Review+2: Thanh Ha <zxiiro@gmail.com> Workflow+1: Thanh Ha <zxiiro@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 13 Jul 2018 14:51:48 +0000 Reviewed-on: https://review.openstack.org/580839 Project: openstack-infra/jenkins-job-builder Branch: refs/heads/master
-rw-r--r--jenkins_jobs/modules/triggers.py32
-rw-r--r--tests/triggers/fixtures/ivy.xml2
2 files changed, 16 insertions, 18 deletions
diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py
index cf7db98..a888b8f 100644
--- a/jenkins_jobs/modules/triggers.py
+++ b/jenkins_jobs/modules/triggers.py
@@ -1727,23 +1727,21 @@ def ivy(registry, xml_parent, data):
1727 """ 1727 """
1728 it = XML.SubElement(xml_parent, 1728 it = XML.SubElement(xml_parent,
1729 'org.jenkinsci.plugins.ivytrigger.IvyTrigger') 1729 'org.jenkinsci.plugins.ivytrigger.IvyTrigger')
1730 mappings = [('path', 'ivyPath', None), 1730 mapping = [
1731 ('settings-path', 'ivySettingsPath', None), 1731 ('path', 'ivyPath', None),
1732 ('properties-file', 'propertiesFilePath', None), 1732 ('settings-path', 'ivySettingsPath', None),
1733 ('properties-content', 'propertiesContent', None), 1733 ('properties-content', 'propertiesContent', None),
1734 ('debug', 'debug', False), 1734 ('debug', 'debug', False),
1735 ('download-artifacts', 'downloadArtifacts', True), 1735 ('download-artifacts', 'downloadArtifacts', True),
1736 ('enable-concurrent', 'enableConcurrentBuild', False), 1736 ('enable-concurrent', 'enableConcurrentBuild', False),
1737 ('cron', 'spec', '')] 1737 ('cron', 'spec', ''),
1738 for prop in mappings: 1738 ]
1739 opt, xmlopt, default_val = prop[:3] 1739 convert_mapping_to_xml(it, data, mapping, fail_required=False)
1740 val = data.get(opt, default_val) 1740
1741 if val is not None: 1741 properties_file_path = data.get('properties-file', [])
1742 if type(val) == bool: 1742 XML.SubElement(it, 'propertiesFilePath').text = ";".join(
1743 val = str(val).lower() 1743 properties_file_path)
1744 if type(val) == list: 1744
1745 val = ";".join(val)
1746 XML.SubElement(it, xmlopt).text = val
1747 label = data.get('label') 1745 label = data.get('label')
1748 XML.SubElement(it, 'labelRestriction').text = str(bool(label)).lower() 1746 XML.SubElement(it, 'labelRestriction').text = str(bool(label)).lower()
1749 if label: 1747 if label:
diff --git a/tests/triggers/fixtures/ivy.xml b/tests/triggers/fixtures/ivy.xml
index ae37a1c..47a8651 100644
--- a/tests/triggers/fixtures/ivy.xml
+++ b/tests/triggers/fixtures/ivy.xml
@@ -4,11 +4,11 @@
4 <org.jenkinsci.plugins.ivytrigger.IvyTrigger> 4 <org.jenkinsci.plugins.ivytrigger.IvyTrigger>
5 <ivyPath>path/to/file</ivyPath> 5 <ivyPath>path/to/file</ivyPath>
6 <ivySettingsPath>path/to/settings/file</ivySettingsPath> 6 <ivySettingsPath>path/to/settings/file</ivySettingsPath>
7 <propertiesFilePath>filename1;filename2</propertiesFilePath>
8 <debug>true</debug> 7 <debug>true</debug>
9 <downloadArtifacts>true</downloadArtifacts> 8 <downloadArtifacts>true</downloadArtifacts>
10 <enableConcurrentBuild>false</enableConcurrentBuild> 9 <enableConcurrentBuild>false</enableConcurrentBuild>
11 <spec>H/15 * * * *</spec> 10 <spec>H/15 * * * *</spec>
11 <propertiesFilePath>filename1;filename2</propertiesFilePath>
12 <labelRestriction>true</labelRestriction> 12 <labelRestriction>true</labelRestriction>
13 <triggerLabel>master</triggerLabel> 13 <triggerLabel>master</triggerLabel>
14 </org.jenkinsci.plugins.ivytrigger.IvyTrigger> 14 </org.jenkinsci.plugins.ivytrigger.IvyTrigger>