summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Miotto <thiagomiottoam@gmail.com>2019-02-21 17:26:03 -0300
committerThiago Miotto <thiagomiottoam@gmail.com>2019-02-22 12:03:11 -0300
commit0f2c43fccf5e9b11332c3e69be5a419a281f9c85 (patch)
treeb22ca6b611df70340eb480b7467a67027cfe8ed4
parentc59b5a5258c875d814b1ada82fd7bbaf7de97a26 (diff)
Adds match-script and groovy-sandbox to Lockable Resources Plugin properties
Notes
Notes (review): Code-Review+2: Thanh Ha (zxiiro) <zxiiro@gmail.com> Workflow+1: Thanh Ha (zxiiro) <zxiiro@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 01 Mar 2019 20:51:55 +0000 Reviewed-on: https://review.openstack.org/638672 Project: openstack-infra/jenkins-job-builder Branch: refs/heads/master
-rw-r--r--jenkins_jobs/modules/properties.py16
-rw-r--r--tests/properties/fixtures/lockable_resources_full.xml3
-rw-r--r--tests/properties/fixtures/lockable_resources_groovy.xml15
-rw-r--r--tests/properties/fixtures/lockable_resources_groovy.yaml5
-rw-r--r--tests/properties/fixtures/lockable_resources_label.xml3
-rw-r--r--tests/properties/fixtures/lockable_resources_minimal.xml3
6 files changed, 45 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py
index 032b6b5..2df88d0 100644
--- a/jenkins_jobs/modules/properties.py
+++ b/jenkins_jobs/modules/properties.py
@@ -1103,6 +1103,10 @@ def lockable_resources(registry, xml_parent, data):
1103 :arg int number: Number of resources to request, empty value or 0 means 1103 :arg int number: Number of resources to request, empty value or 0 means
1104 all. This is useful, if you have a pool of similar resources, 1104 all. This is useful, if you have a pool of similar resources,
1105 from which you want one or more to be reserved. (default 0) 1105 from which you want one or more to be reserved. (default 0)
1106 :arg str match-script: Groovy script to reserve resource based on its
1107 properties. Leave empty to disable. (default None)
1108 :arg bool groovy-sandbox: Execute the provided match-script in Groovy
1109 sandbox. Leave empty to disable. (default False)
1106 1110
1107 Example: 1111 Example:
1108 1112
@@ -1117,6 +1121,10 @@ def lockable_resources(registry, xml_parent, data):
1117 .. literalinclude:: 1121 .. literalinclude::
1118 /../../tests/properties/fixtures/lockable_resources_full.yaml 1122 /../../tests/properties/fixtures/lockable_resources_full.yaml
1119 :language: yaml 1123 :language: yaml
1124
1125 .. literalinclude::
1126 /../../tests/properties/fixtures/lockable_resources_groovy.yaml
1127 :language: yaml
1120 """ 1128 """
1121 lockable_resources = XML.SubElement( 1129 lockable_resources = XML.SubElement(
1122 xml_parent, 1130 xml_parent,
@@ -1131,6 +1139,14 @@ def lockable_resources(registry, xml_parent, data):
1131 ] 1139 ]
1132 helpers.convert_mapping_to_xml( 1140 helpers.convert_mapping_to_xml(
1133 lockable_resources, data, mapping, fail_required=True) 1141 lockable_resources, data, mapping, fail_required=True)
1142 secure_groovy_script = XML.SubElement(lockable_resources,
1143 'resourceMatchScript')
1144 mapping = [
1145 ('match-script', 'script', None),
1146 ('groovy-sandbox', 'sandbox', False),
1147 ]
1148 helpers.convert_mapping_to_xml(secure_groovy_script, data, mapping,
1149 fail_required=False)
1134 1150
1135 1151
1136def docker_container(registry, xml_parent, data): 1152def docker_container(registry, xml_parent, data):
diff --git a/tests/properties/fixtures/lockable_resources_full.xml b/tests/properties/fixtures/lockable_resources_full.xml
index 11760a9..726a93a 100644
--- a/tests/properties/fixtures/lockable_resources_full.xml
+++ b/tests/properties/fixtures/lockable_resources_full.xml
@@ -6,6 +6,9 @@
6 <resourceNamesVar>RESOURCE_NAME</resourceNamesVar> 6 <resourceNamesVar>RESOURCE_NAME</resourceNamesVar>
7 <resourceNumber>10</resourceNumber> 7 <resourceNumber>10</resourceNumber>
8 <labelName/> 8 <labelName/>
9 <resourceMatchScript>
10 <sandbox>false</sandbox>
11 </resourceMatchScript>
9 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty> 12 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
10 </properties> 13 </properties>
11</project> 14</project>
diff --git a/tests/properties/fixtures/lockable_resources_groovy.xml b/tests/properties/fixtures/lockable_resources_groovy.xml
new file mode 100644
index 0000000..71c4100
--- /dev/null
+++ b/tests/properties/fixtures/lockable_resources_groovy.xml
@@ -0,0 +1,15 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <properties>
4 <org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
5 <resourceNames/>
6 <resourceNamesVar/>
7 <resourceNumber>0</resourceNumber>
8 <labelName/>
9 <resourceMatchScript>
10 <script>resourceName == MY_VAR</script>
11 <sandbox>true</sandbox>
12 </resourceMatchScript>
13 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
14 </properties>
15</project>
diff --git a/tests/properties/fixtures/lockable_resources_groovy.yaml b/tests/properties/fixtures/lockable_resources_groovy.yaml
new file mode 100644
index 0000000..ceec1e4
--- /dev/null
+++ b/tests/properties/fixtures/lockable_resources_groovy.yaml
@@ -0,0 +1,5 @@
1---
2properties:
3 - lockable-resources:
4 match-script: "resourceName == MY_VAR"
5 groovy-sandbox: true
diff --git a/tests/properties/fixtures/lockable_resources_label.xml b/tests/properties/fixtures/lockable_resources_label.xml
index 903e732..f833c7c 100644
--- a/tests/properties/fixtures/lockable_resources_label.xml
+++ b/tests/properties/fixtures/lockable_resources_label.xml
@@ -6,6 +6,9 @@
6 <resourceNamesVar/> 6 <resourceNamesVar/>
7 <resourceNumber>0</resourceNumber> 7 <resourceNumber>0</resourceNumber>
8 <labelName>pool-1</labelName> 8 <labelName>pool-1</labelName>
9 <resourceMatchScript>
10 <sandbox>false</sandbox>
11 </resourceMatchScript>
9 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty> 12 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
10 </properties> 13 </properties>
11</project> 14</project>
diff --git a/tests/properties/fixtures/lockable_resources_minimal.xml b/tests/properties/fixtures/lockable_resources_minimal.xml
index df64ff5..ed8e2d4 100644
--- a/tests/properties/fixtures/lockable_resources_minimal.xml
+++ b/tests/properties/fixtures/lockable_resources_minimal.xml
@@ -6,6 +6,9 @@
6 <resourceNamesVar/> 6 <resourceNamesVar/>
7 <resourceNumber>0</resourceNumber> 7 <resourceNumber>0</resourceNumber>
8 <labelName/> 8 <labelName/>
9 <resourceMatchScript>
10 <sandbox>false</sandbox>
11 </resourceMatchScript>
9 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty> 12 </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
10 </properties> 13 </properties>
11</project> 14</project>