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

Change-Id: I45db7b1a58f2dea4d46aba61aaf16383d30f1b50
This commit is contained in:
Thiago Miotto 2019-02-21 17:26:03 -03:00
parent c59b5a5258
commit 0f2c43fccf
6 changed files with 45 additions and 0 deletions

View File

@ -1103,6 +1103,10 @@ def lockable_resources(registry, xml_parent, data):
:arg int number: Number of resources to request, empty value or 0 means
all. This is useful, if you have a pool of similar resources,
from which you want one or more to be reserved. (default 0)
:arg str match-script: Groovy script to reserve resource based on its
properties. Leave empty to disable. (default None)
:arg bool groovy-sandbox: Execute the provided match-script in Groovy
sandbox. Leave empty to disable. (default False)
Example:
@ -1117,6 +1121,10 @@ def lockable_resources(registry, xml_parent, data):
.. literalinclude::
/../../tests/properties/fixtures/lockable_resources_full.yaml
:language: yaml
.. literalinclude::
/../../tests/properties/fixtures/lockable_resources_groovy.yaml
:language: yaml
"""
lockable_resources = XML.SubElement(
xml_parent,
@ -1131,6 +1139,14 @@ def lockable_resources(registry, xml_parent, data):
]
helpers.convert_mapping_to_xml(
lockable_resources, data, mapping, fail_required=True)
secure_groovy_script = XML.SubElement(lockable_resources,
'resourceMatchScript')
mapping = [
('match-script', 'script', None),
('groovy-sandbox', 'sandbox', False),
]
helpers.convert_mapping_to_xml(secure_groovy_script, data, mapping,
fail_required=False)
def docker_container(registry, xml_parent, data):

View File

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

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
<resourceNames/>
<resourceNamesVar/>
<resourceNumber>0</resourceNumber>
<labelName/>
<resourceMatchScript>
<script>resourceName == MY_VAR</script>
<sandbox>true</sandbox>
</resourceMatchScript>
</org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
</properties>
</project>

View File

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

View File

@ -6,6 +6,9 @@
<resourceNamesVar/>
<resourceNumber>0</resourceNumber>
<labelName>pool-1</labelName>
<resourceMatchScript>
<sandbox>false</sandbox>
</resourceMatchScript>
</org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
</properties>
</project>

View File

@ -6,6 +6,9 @@
<resourceNamesVar/>
<resourceNumber>0</resourceNumber>
<labelName/>
<resourceMatchScript>
<sandbox>false</sandbox>
</resourceMatchScript>
</org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
</properties>
</project>