diff options
author | Zuul <zuul@review.opendev.org> | 2020-07-15 14:13:47 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2020-07-15 14:13:47 +0000 |
commit | 435dc40b75a54cf57c0ae95377566b1be2e3304b (patch) | |
tree | 94148b76ffb76dd57ec9c1aa91f701052f402c82 | |
parent | 784a38ecc9ca72c0f818ec4a25caf768e70b64dd (diff) | |
parent | 52caa12068b750cb3174c7d434bb0ba0aace82ee (diff) | |
download | python-jenkins-job-builder-435dc40b75a54cf57c0ae95377566b1be2e3304b.tar.gz python-jenkins-job-builder-435dc40b75a54cf57c0ae95377566b1be2e3304b.tar.xz python-jenkins-job-builder-435dc40b75a54cf57c0ae95377566b1be2e3304b.zip |
Merge "publishers: refactor out a helpers.trigger_threshold() helper"
-rw-r--r-- | jenkins_jobs/modules/helpers.py | 21 | ||||
-rwxr-xr-x | jenkins_jobs/modules/publishers.py | 14 |
2 files changed, 24 insertions, 11 deletions
diff --git a/jenkins_jobs/modules/helpers.py b/jenkins_jobs/modules/helpers.py index 10945c71..258b13cb 100644 --- a/jenkins_jobs/modules/helpers.py +++ b/jenkins_jobs/modules/helpers.py @@ -19,6 +19,7 @@ import xml.etree.ElementTree as XML from jenkins_jobs.errors import InvalidAttributeError from jenkins_jobs.errors import JenkinsJobsException from jenkins_jobs.errors import MissingAttributeError +from jenkins_jobs.modules import hudson_model def build_trends_publisher(plugin_name, xml_element, data): @@ -613,6 +614,26 @@ def trigger_project(tconfigs, project_def, param_order=None): ) +def trigger_threshold( + parent_element, element_name, threshold_name, supported_thresholds=None +): + """Generate a resultThreshold XML element for build/join triggers""" + element = XML.SubElement(parent_element, element_name) + + try: + threshold = hudson_model.THRESHOLDS[threshold_name.upper()] + except KeyError: + if not supported_thresholds: + supported_thresholds = hudson_model.THRESHOLDS.keys() + raise JenkinsJobsException( + "threshold must be one of %s" % ", ".join(supported_thresholds) + ) + XML.SubElement(element, "name").text = threshold["name"] + XML.SubElement(element, "ordinal").text = threshold["ordinal"] + XML.SubElement(element, "color").text = threshold["color"] + return element + + def convert_mapping_to_xml(parent, data, mapping, fail_required=True): """Convert mapping to XML diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 68b93e73..a9254d62 100755 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -608,20 +608,12 @@ def trigger(registry, xml_parent, data): tconfig = XML.SubElement(xml_parent, "hudson.tasks.BuildTrigger") childProjects = XML.SubElement(tconfig, "childProjects") childProjects.text = data["project"] - tthreshold = XML.SubElement(tconfig, "threshold") threshold = data.get("threshold", "SUCCESS") supported_thresholds = ["SUCCESS", "UNSTABLE", "FAILURE"] - if threshold not in supported_thresholds: - raise JenkinsJobsException( - "threshold must be one of %s" % ", ".join(supported_thresholds) - ) - tname = XML.SubElement(tthreshold, "name") - tname.text = hudson_model.THRESHOLDS[threshold]["name"] - tordinal = XML.SubElement(tthreshold, "ordinal") - tordinal.text = hudson_model.THRESHOLDS[threshold]["ordinal"] - tcolor = XML.SubElement(tthreshold, "color") - tcolor.text = hudson_model.THRESHOLDS[threshold]["color"] + helpers.trigger_threshold( + tconfig, "threshold", threshold, supported_thresholds=supported_thresholds + ) def clone_workspace(registry, xml_parent, data): |