diff --git a/jenkins_jobs/modules/properties.py b/jenkins_jobs/modules/properties.py index 8e06385eb..22192e125 100644 --- a/jenkins_jobs/modules/properties.py +++ b/jenkins_jobs/modules/properties.py @@ -1217,6 +1217,41 @@ def disable_resume(registry, xml_parent, data): 'DisableResumeJobProperty') +def cachet_gating(registry, xml_parent, data): + """yaml: cachet-gating + The Cachet Gating Plugin provides a gating mechanism + based on the availability of resources. + + Requires the Jenkins: :jenkins-wiki:`Cachet Gate Plugin + `. + + :arg bool required-resources: Confirm availability of listed + resources before building. Requires the list of resources to + also be defined. (default true) + :arg list resources: which resources to gate + + Example: + + .. literalinclude:: /../../tests/properties/fixtures/cachet-gating.yaml + :language: yaml + """ + cachet = XML.SubElement( + xml_parent, 'com.redhat.jenkins.plugins.cachet.CachetJobProperty') + cachet.set('plugin', 'cachet-gating') + + mapping = [ + ('required-resources', 'requiredResources', True), + ] + helpers.convert_mapping_to_xml( + cachet, data, mapping, fail_required=True) + + resources_data = data.get('resources', []) + if resources_data: + resources = XML.SubElement(cachet, 'resources') + for resource in resources_data: + XML.SubElement(resources, 'string').text = str(resource) + + class Properties(jenkins_jobs.modules.base.Base): sequence = 20 diff --git a/tests/properties/fixtures/cachet-gating.xml b/tests/properties/fixtures/cachet-gating.xml new file mode 100644 index 000000000..d71a34437 --- /dev/null +++ b/tests/properties/fixtures/cachet-gating.xml @@ -0,0 +1,12 @@ + + + + + true + + beaker + brew + + + + diff --git a/tests/properties/fixtures/cachet-gating.yaml b/tests/properties/fixtures/cachet-gating.yaml new file mode 100644 index 000000000..8c514cd91 --- /dev/null +++ b/tests/properties/fixtures/cachet-gating.yaml @@ -0,0 +1,6 @@ +properties: + - cachet-gating: + required-resources: true + resources: + - beaker + - brew