Add support to customize trigger-builds block thresholds

Updated trigger-builds function to support customization of
thresholds sub sections under block section

Currently JJB only set default values to those three block thresholds.
There are sometimes need to set different values than default.

Change-Id: I73e7f828c6b651b87e7068d3c16362f4901ba32a
This commit is contained in:
Jon Nessmar 2015-02-06 13:46:02 +01:00 committed by David Pursehouse
parent 9cbba31054
commit d76fa3da74
16 changed files with 126 additions and 22 deletions

View File

@ -298,6 +298,16 @@ def trigger_builds(parser, xml_parent, data):
to the triggered job
:arg bool block: whether to wait for the triggered jobs
to finish or not (default false)
:arg dict block-thresholds: Fail builds and/or mark as failed or unstable
based on thresholds. Only apply if block parameter is true (optional)
* **build-step-failure-threshold** (`str`)
['never', 'SUCCESS', 'UNSTABLE', 'FAILURE'] (default: 'FAILURE')
* **unstable-threshold** (`str`)
['never', 'SUCCESS', 'UNSTABLE', 'FAILURE'] (default: 'UNSTABLE')
* **failure-threshold** (`str`)
['never', 'SUCCESS', 'UNSTABLE', 'FAILURE'] (default: 'FAILURE')
:arg bool same-node: Use the same node for the triggered builds that was
used for this build (optional)
:arg list parameter-factories: list of parameter factories
@ -484,29 +494,40 @@ def trigger_builds(parser, xml_parent, data):
'buildAllNodesWithLabel')
build_all_nodes_with_label.text = 'false'
block = project_def.get('block', False)
if(block):
if block:
block = XML.SubElement(tconfig, 'block')
bsft = XML.SubElement(block, 'buildStepFailureThreshold')
XML.SubElement(bsft, 'name').text = \
hudson_model.FAILURE['name']
XML.SubElement(bsft, 'ordinal').text = \
hudson_model.FAILURE['ordinal']
XML.SubElement(bsft, 'color').text = \
hudson_model.FAILURE['color']
ut = XML.SubElement(block, 'unstableThreshold')
XML.SubElement(ut, 'name').text = \
hudson_model.UNSTABLE['name']
XML.SubElement(ut, 'ordinal').text = \
hudson_model.UNSTABLE['ordinal']
XML.SubElement(ut, 'color').text = \
hudson_model.UNSTABLE['color']
ft = XML.SubElement(block, 'failureThreshold')
XML.SubElement(ft, 'name').text = \
hudson_model.FAILURE['name']
XML.SubElement(ft, 'ordinal').text = \
hudson_model.FAILURE['ordinal']
XML.SubElement(ft, 'color').text = \
hudson_model.FAILURE['color']
supported_thresholds = [['build-step-failure-threshold',
'buildStepFailureThreshold',
'FAILURE'],
['unstable-threshold',
'unstableThreshold',
'UNSTABLE'],
['failure-threshold',
'failureThreshold',
'FAILURE']]
supported_threshold_values = ['never',
hudson_model.SUCCESS['name'],
hudson_model.UNSTABLE['name'],
hudson_model.FAILURE['name']]
thrsh = project_def.get('block-thresholds', False)
for toptname, txmltag, tvalue in supported_thresholds:
if thrsh:
tvalue = thrsh.get(toptname, tvalue)
if tvalue.lower() == supported_threshold_values[0]:
continue
if tvalue.upper() not in supported_threshold_values:
raise JenkinsJobsException(
"threshold value must be one of (%s)" %
", ".join(supported_threshold_values))
th = XML.SubElement(block, txmltag)
XML.SubElement(th, 'name').text = hudson_model.THRESHOLDS[
tvalue.upper()]['name']
XML.SubElement(th, 'ordinal').text = hudson_model.THRESHOLDS[
tvalue.upper()]['ordinal']
XML.SubElement(th, 'color').text = hudson_model.THRESHOLDS[
tvalue.upper()]['color']
XML.SubElement(th, 'completeBuild').text = "true"
# If configs is empty, remove the entire tbuilder tree.
if(len(configs) == 0):
logger.debug("Pruning empty TriggerBuilder tree.")

View File

@ -21,16 +21,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -21,16 +21,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -21,16 +21,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -21,16 +21,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -25,16 +25,19 @@ HELLO=WORLD
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -23,16 +23,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -20,16 +20,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -20,16 +20,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -43,16 +43,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -20,16 +20,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -19,16 +19,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -19,16 +19,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -19,16 +19,19 @@
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<unstableThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</unstableThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<hudson.plugins.parameterizedtrigger.TriggerBuilder>
<configs>
<hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
<configs>
<hudson.plugins.parameterizedtrigger.FileBuildParameters>
<propertiesFile>propfile.txt</propertiesFile>
<failTriggerOnMissing>true</failTriggerOnMissing>
</hudson.plugins.parameterizedtrigger.FileBuildParameters>
</configs>
<projects>build_started</projects>
<condition>ALWAYS</condition>
<triggerWithNoParameters>false</triggerWithNoParameters>
<buildAllNodesWithLabel>false</buildAllNodesWithLabel>
<block>
<buildStepFailureThreshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</buildStepFailureThreshold>
<failureThreshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</failureThreshold>
</block>
</hudson.plugins.parameterizedtrigger.BlockableBuildTriggerConfig>
</configs>
</hudson.plugins.parameterizedtrigger.TriggerBuilder>
</builders>
</project>

View File

@ -0,0 +1,9 @@
builders:
- trigger-builds:
- project: "build_started"
property-file: propfile.txt
block: true
block-thresholds:
build-step-failure-threshold: UNSTABLE
unstable-threshold: never
failure-threshold: FAILURE