Merge "publishers: refactor out a helpers.trigger_threshold() helper"
This commit is contained in:
commit
435dc40b75
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user