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) :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: .. 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 .. literalinclude:: /../../tests/properties/fixtures/lockable_resources_groovy.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) 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 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',)) XML.SubElement( lockable_resources, 'resourceNames').text = data.get('resources', '') XML.SubElement( lockable_resources, 'resourceNamesVar').text = data.get('var-name', '') XML.SubElement( lockable_resources, 'resourceNumber').text = str(data.get('number', 0)) XML.SubElement( lockable_resources, 'labelName').text = data.get('label', '')