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 to the triggered job
:arg bool block: whether to wait for the triggered jobs :arg bool block: whether to wait for the triggered jobs
to finish or not (default false) 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 :arg bool same-node: Use the same node for the triggered builds that was
used for this build (optional) used for this build (optional)
:arg list parameter-factories: list of parameter factories :arg list parameter-factories: list of parameter factories
@ -484,29 +494,40 @@ def trigger_builds(parser, xml_parent, data):
'buildAllNodesWithLabel') 'buildAllNodesWithLabel')
build_all_nodes_with_label.text = 'false' build_all_nodes_with_label.text = 'false'
block = project_def.get('block', False) block = project_def.get('block', False)
if(block): if block:
block = XML.SubElement(tconfig, 'block') block = XML.SubElement(tconfig, 'block')
bsft = XML.SubElement(block, 'buildStepFailureThreshold') supported_thresholds = [['build-step-failure-threshold',
XML.SubElement(bsft, 'name').text = \ 'buildStepFailureThreshold',
hudson_model.FAILURE['name'] 'FAILURE'],
XML.SubElement(bsft, 'ordinal').text = \ ['unstable-threshold',
hudson_model.FAILURE['ordinal'] 'unstableThreshold',
XML.SubElement(bsft, 'color').text = \ 'UNSTABLE'],
hudson_model.FAILURE['color'] ['failure-threshold',
ut = XML.SubElement(block, 'unstableThreshold') 'failureThreshold',
XML.SubElement(ut, 'name').text = \ 'FAILURE']]
hudson_model.UNSTABLE['name'] supported_threshold_values = ['never',
XML.SubElement(ut, 'ordinal').text = \ hudson_model.SUCCESS['name'],
hudson_model.UNSTABLE['ordinal'] hudson_model.UNSTABLE['name'],
XML.SubElement(ut, 'color').text = \ hudson_model.FAILURE['name']]
hudson_model.UNSTABLE['color'] thrsh = project_def.get('block-thresholds', False)
ft = XML.SubElement(block, 'failureThreshold') for toptname, txmltag, tvalue in supported_thresholds:
XML.SubElement(ft, 'name').text = \ if thrsh:
hudson_model.FAILURE['name'] tvalue = thrsh.get(toptname, tvalue)
XML.SubElement(ft, 'ordinal').text = \ if tvalue.lower() == supported_threshold_values[0]:
hudson_model.FAILURE['ordinal'] continue
XML.SubElement(ft, 'color').text = \ if tvalue.upper() not in supported_threshold_values:
hudson_model.FAILURE['color'] 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 configs is empty, remove the entire tbuilder tree.
if(len(configs) == 0): if(len(configs) == 0):
logger.debug("Pruning empty TriggerBuilder tree.") logger.debug("Pruning empty TriggerBuilder tree.")

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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