From c907f7708c2f6cdaaa91fab4506982026de84044 Mon Sep 17 00:00:00 2001 From: Aviel Yosef Date: Wed, 17 Jul 2019 09:24:29 +0300 Subject: [PATCH] Adding support for the cachet gating plugin Change-Id: Ie50d25d09a094f2315e790288f3c3f1619ffdb7f --- jenkins_jobs/modules/properties.py | 35 ++++++++++++++++++++ tests/properties/fixtures/cachet-gating.xml | 12 +++++++ tests/properties/fixtures/cachet-gating.yaml | 6 ++++ 3 files changed, 53 insertions(+) create mode 100644 tests/properties/fixtures/cachet-gating.xml create mode 100644 tests/properties/fixtures/cachet-gating.yaml 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