Merge "properties: cover lockable-resources plugin"

This commit is contained in:
Jenkins 2017-03-28 19:03:05 +00:00 committed by Gerrit Code Review
commit 7f275c3236
8 changed files with 112 additions and 0 deletions

View File

@ -65,6 +65,24 @@ class MissingAttributeError(ModuleError):
super(MissingAttributeError, self).__init__(message) super(MissingAttributeError, self).__init__(message)
class AttributeConflictError(ModuleError):
def __init__(
self, attribute_name, attributes_in_conflict, module_name=None
):
module = module_name or self.get_module_name()
message = (
"Attribute '{0}' can not be used together with {1} in {2}".format(
attribute_name,
', '.join(
"'{0}'".format(value) for value in attributes_in_conflict
), module
)
)
super(AttributeConflictError, self).__init__(message)
class YAMLFormatError(JenkinsJobsException): class YAMLFormatError(JenkinsJobsException):
pass pass

View File

@ -38,6 +38,7 @@ import xml.etree.ElementTree as XML
from jenkins_jobs.errors import InvalidAttributeError from jenkins_jobs.errors import InvalidAttributeError
from jenkins_jobs.errors import JenkinsJobsException from jenkins_jobs.errors import JenkinsJobsException
from jenkins_jobs.errors import MissingAttributeError from jenkins_jobs.errors import MissingAttributeError
from jenkins_jobs.errors import AttributeConflictError
import jenkins_jobs.modules.base import jenkins_jobs.modules.base
import jenkins_jobs.modules.helpers as helpers import jenkins_jobs.modules.helpers as helpers
@ -946,6 +947,52 @@ def groovy_label(registry, xml_parent, data):
XML.SubElement(entry, 'url').text = value XML.SubElement(entry, 'url').text = value
def lockable_resources(registry, xml_parent, data):
"""yaml: lockable-resources
Requires the Jenkins :jenkins-wiki:`Lockable Resources Plugin
<Lockable+Resources+Plugin>`.
:arg str resources: List of required resources, space separated.
(required, mutual exclusive with label)
:arg str label: If you have created a pool of resources, i.e. a label,
you can take it into use here. The build will select the resource(s)
from the pool that includes all resources sharing the given label.
(required, mutual exclusive with resources)
:arg str var-name: Name for the Jenkins variable to store the reserved
resources in. Leave empty to disable. (default '')
: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)
Example:
.. literalinclude::
/../../tests/properties/fixtures/lockable_resources_minimal.yaml
:language: yaml
.. literalinclude::
/../../tests/properties/fixtures/lockable_resources_label.yaml
:language: yaml
.. literalinclude::
/../../tests/properties/fixtures/lockable_resources_full.yaml
:language: yaml
"""
lockable_resources = XML.SubElement(
xml_parent,
'org.jenkins.plugins.lockableresources.RequiredResourcesProperty')
if data.get('resources') and data.get('label'):
raise AttributeConflictError('resources', ('label',))
mapping = [
('resources', 'resourceNames', ''),
('var-name', 'resourceNamesVar', ''),
('number', 'resourceNumber', 0),
('label', 'labelName', ''),
]
helpers.convert_mapping_to_xml(
lockable_resources, data, mapping, fail_required=True)
class Properties(jenkins_jobs.modules.base.Base): class Properties(jenkins_jobs.modules.base.Base):
sequence = 20 sequence = 20

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
<resourceNames>the-resource</resourceNames>
<resourceNamesVar>RESOURCE_NAME</resourceNamesVar>
<resourceNumber>10</resourceNumber>
<labelName/>
</org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
</properties>
</project>

View File

@ -0,0 +1,6 @@
---
properties:
- lockable-resources:
resources: "the-resource"
var-name: "RESOURCE_NAME"
number: 10

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
<resourceNames/>
<resourceNamesVar/>
<resourceNumber>0</resourceNumber>
<labelName>pool-1</labelName>
</org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
</properties>
</project>

View File

@ -0,0 +1,4 @@
---
properties:
- lockable-resources:
label: "pool-1"

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
<resourceNames>the-resource</resourceNames>
<resourceNamesVar/>
<resourceNumber>0</resourceNumber>
<labelName/>
</org.jenkins.plugins.lockableresources.RequiredResourcesProperty>
</properties>
</project>

View File

@ -0,0 +1,4 @@
---
properties:
- lockable-resources:
resources: "the-resource"