Initial work for supporting downstream-ext

Change-Id: Icdb1421d627bc93237cbf79de9d319f44c98ae01
This commit is contained in:
Max Rydahl Andersen 2015-02-22 12:05:04 +01:00 committed by Darragh Bailey
parent d976466c10
commit 159190280c
6 changed files with 118 additions and 0 deletions

View File

@ -3768,6 +3768,76 @@ def shining_panda(parser, xml_parent, data):
data['html-reports-directory'])
def downstream_ext(parser, xml_parent, data):
"""yaml: downstream-ext
Trigger multiple downstream jobs when a job is completed and
condition is met.
Requires the Jenkins :jenkins-wiki:`Downstream-Ext Plugin
<Downstream-Ext+Plugin>`.
:arg list projects: Projects to build (required)
:arg string comparison: comparison used for the criteria.
One of 'equal-or-over', 'equal-or-under', 'equal'
(default: 'equal-or-over')
:arg string criteria: Trigger downstream job if build results meets
condition. One of 'success', 'unstable', 'failure' or
'aborted' (default: 'success')
:arg bool only-on-scm-change: Trigger only if downstream project
has SCM changes (default: false)
:arg bool only-on-local-scm-change: Trigger only if current project
has SCM changes (default: false)
Example:
.. literalinclude::
/../../tests/publishers/fixtures/downstream-ext002.yaml
:language: yaml
"""
conditions = {
"equal-or-over": "AND_HIGHER",
"equal-or-under": "AND_LOWER",
"equal": "EQUAL"
}
p = XML.SubElement(xml_parent,
'hudson.plugins.downstream__ext.DownstreamTrigger')
if 'projects' not in data:
raise JenkinsJobsException("Missing list of downstream projects.")
XML.SubElement(p, 'childProjects').text = ','.join(data['projects'])
th = XML.SubElement(p, 'threshold')
criteria = data.get('criteria', 'success').upper()
if criteria not in hudson_model.THRESHOLDS:
raise JenkinsJobsException("criteria must be one of %s" %
", ".join(hudson_model.THRESHOLDS.keys()))
wr_threshold = hudson_model.THRESHOLDS[
criteria]
XML.SubElement(th, "name").text = wr_threshold['name']
XML.SubElement(th, "ordinal").text = wr_threshold['ordinal']
XML.SubElement(th, "color").text = wr_threshold['color']
XML.SubElement(th, "completeBuild").text = str(
wr_threshold['complete']).lower()
condition = data.get('condition', 'equal-or-over')
if condition not in conditions:
raise JenkinsJobsException('condition must be one of: %s' %
", ".join(conditions))
XML.SubElement(p, 'thresholdStrategy').text = conditions[
condition]
XML.SubElement(p, 'onlyIfSCMChanges').text = str(
data.get('only-on-scm-change', False)).lower()
XML.SubElement(p, 'onlyIfLocalSCMChanges').text = str(
data.get('only-on-local-scm-change', False)).lower()
def create_publishers(parser, action):
dummy_parent = XML.Element("dummy")
parser.registry.dispatch('publisher', parser, dummy_parent, action)

View File

@ -138,6 +138,7 @@ jenkins_jobs.publishers =
coverage=jenkins_jobs.modules.publishers:coverage
cppcheck=jenkins_jobs.modules.publishers:cppcheck
description-setter=jenkins_jobs.modules.publishers:description_setter
downstream-ext=jenkins_jobs.modules.publishers:downstream_ext
doxygen=jenkins_jobs.modules.publishers:doxygen
dry=jenkins_jobs.modules.publishers:dry
email-ext=jenkins_jobs.modules.publishers:email_ext

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.downstream__ext.DownstreamTrigger>
<childProjects>foo,bar</childProjects>
<threshold>
<name>SUCCESS</name>
<ordinal>0</ordinal>
<color>BLUE</color>
<completeBuild>true</completeBuild>
</threshold>
<thresholdStrategy>AND_HIGHER</thresholdStrategy>
<onlyIfSCMChanges>false</onlyIfSCMChanges>
<onlyIfLocalSCMChanges>false</onlyIfLocalSCMChanges>
</hudson.plugins.downstream__ext.DownstreamTrigger>
</publishers>
</project>

View File

@ -0,0 +1,5 @@
publishers:
- downstream-ext:
projects:
- foo
- bar

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.downstream__ext.DownstreamTrigger>
<childProjects>foo,bar</childProjects>
<threshold>
<name>UNSTABLE</name>
<ordinal>1</ordinal>
<color>YELLOW</color>
<completeBuild>true</completeBuild>
</threshold>
<thresholdStrategy>EQUAL</thresholdStrategy>
<onlyIfSCMChanges>true</onlyIfSCMChanges>
<onlyIfLocalSCMChanges>false</onlyIfLocalSCMChanges>
</hudson.plugins.downstream__ext.DownstreamTrigger>
</publishers>
</project>

View File

@ -0,0 +1,8 @@
publishers:
- downstream-ext:
projects:
- foo
- bar
only-on-scm-change: true
criteria: unstable
condition: equal