Browse Source

Adds match-script and groovy-sandbox to Lockable Resources Plugin properties

Change-Id: I45db7b1a58f2dea4d46aba61aaf16383d30f1b50
tags/2.10.0
Thiago Miotto 3 months ago
parent
commit
0f2c43fccf

+ 16
- 0
jenkins_jobs/modules/properties.py View File

@@ -1103,6 +1103,10 @@ def lockable_resources(registry, xml_parent, data):
1103 1103
     :arg int number: Number of resources to request, empty value or 0 means
1104 1104
         all. This is useful, if you have a pool of similar resources,
1105 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 1111
     Example:
1108 1112
 
@@ -1117,6 +1121,10 @@ def lockable_resources(registry, xml_parent, data):
1117 1121
     .. literalinclude::
1118 1122
         /../../tests/properties/fixtures/lockable_resources_full.yaml
1119 1123
        :language: yaml
1124
+
1125
+    .. literalinclude::
1126
+        /../../tests/properties/fixtures/lockable_resources_groovy.yaml
1127
+       :language: yaml
1120 1128
     """
1121 1129
     lockable_resources = XML.SubElement(
1122 1130
         xml_parent,
@@ -1131,6 +1139,14 @@ def lockable_resources(registry, xml_parent, data):
1131 1139
     ]
1132 1140
     helpers.convert_mapping_to_xml(
1133 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
 
1136 1152
 def docker_container(registry, xml_parent, data):

+ 3
- 0
tests/properties/fixtures/lockable_resources_full.xml View File

@@ -6,6 +6,9 @@
6 6
       <resourceNamesVar>RESOURCE_NAME</resourceNamesVar>
7 7
       <resourceNumber>10</resourceNumber>
8 8
       <labelName/>
9
+      <resourceMatchScript>
10
+        <sandbox>false</sandbox>
11
+      </resourceMatchScript>
9 12
     </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
10 13
   </properties>
11 14
 </project>

+ 15
- 0
tests/properties/fixtures/lockable_resources_groovy.xml View File

@@ -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>

+ 5
- 0
tests/properties/fixtures/lockable_resources_groovy.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+properties:
3
+  - lockable-resources:
4
+      match-script: "resourceName == MY_VAR"
5
+      groovy-sandbox: true

+ 3
- 0
tests/properties/fixtures/lockable_resources_label.xml View File

@@ -6,6 +6,9 @@
6 6
       <resourceNamesVar/>
7 7
       <resourceNumber>0</resourceNumber>
8 8
       <labelName>pool-1</labelName>
9
+      <resourceMatchScript>
10
+        <sandbox>false</sandbox>
11
+      </resourceMatchScript>
9 12
     </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
10 13
   </properties>
11 14
 </project>

+ 3
- 0
tests/properties/fixtures/lockable_resources_minimal.xml View File

@@ -6,6 +6,9 @@
6 6
       <resourceNamesVar/>
7 7
       <resourceNumber>0</resourceNumber>
8 8
       <labelName/>
9
+      <resourceMatchScript>
10
+        <sandbox>false</sandbox>
11
+      </resourceMatchScript>
9 12
     </org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
10 13
   </properties>
11 14
 </project>

Loading…
Cancel
Save