Add support to reverse trigger for job list

Listing jobs as a comma separated list is fine with small amounts of
jobs however when this list gets too long it can be difficult to
maintain.

This patch adds support to list jobs as a list and the code will
automatically change it to a python separated list. Also retains support
for the old style comma separated list.

Change-Id: I0a419bb1f2ec83979f46990430f874381680cac8
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2015-06-24 14:11:42 -04:00 committed by Wayne
parent d54c7a97fe
commit 833fa2b928
3 changed files with 33 additions and 2 deletions
jenkins_jobs/modules
tests/triggers/fixtures

View File

@ -861,13 +861,18 @@ def reverse(parser, xml_parent, data):
"Post-build Actions" of an upstream project, but is preferable when you
want to configure the downstream project.
:arg str jobs: List (comma separated) of jobs to watch.
:arg str jobs: List of jobs to watch. Can be either a comma separated
list or a list.
:arg str result: Build results to monitor for between the following
options: success, unstable and failure. (default 'success').
Example:
.. literalinclude:: /../../tests/triggers/fixtures/reverse.yaml
Example List:
.. literalinclude:: /../../tests/triggers/fixtures/reverse-list.yaml
"""
reserveBuildTrigger = XML.SubElement(
xml_parent, 'jenkins.triggers.ReverseBuildTrigger')
@ -875,8 +880,12 @@ def reverse(parser, xml_parent, data):
supported_thresholds = ['SUCCESS', 'UNSTABLE', 'FAILURE']
XML.SubElement(reserveBuildTrigger, 'spec').text = ''
jobs = data.get('jobs')
if isinstance(jobs, list):
jobs = ",".join(jobs)
XML.SubElement(reserveBuildTrigger, 'upstreamProjects').text = \
data.get('jobs')
jobs
threshold = XML.SubElement(reserveBuildTrigger, 'threshold')
result = data.get('result').upper()

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<triggers class="vector">
<jenkins.triggers.ReverseBuildTrigger>
<spec/>
<upstreamProjects>a,b,c</upstreamProjects>
<threshold>
<name>FAILURE</name>
<ordinal>2</ordinal>
<color>RED</color>
<completeBuild>true</completeBuild>
</threshold>
</jenkins.triggers.ReverseBuildTrigger>
</triggers>
</project>

View File

@ -0,0 +1,7 @@
triggers:
- reverse:
jobs:
- 'a'
- 'b'
- 'c'
result: 'failure'