Add support for reverse build trigger
Change-Id: I06d9969df0e9edfca2a2b433e2a13e3bc10c8b2c
This commit is contained in:
parent
04139e0f5e
commit
57501a94f3
@ -32,6 +32,7 @@ Example::
|
||||
|
||||
import xml.etree.ElementTree as XML
|
||||
import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules import hudson_model
|
||||
import logging
|
||||
import re
|
||||
|
||||
@ -474,6 +475,52 @@ def build_result(parser, xml_parent, data):
|
||||
XML.SubElement(model_checked, 'checked').text = result_dict[result]
|
||||
|
||||
|
||||
def reverse(parser, xml_parent, data):
|
||||
"""yaml: reverse
|
||||
This trigger can be configured in the UI using the checkbox with the
|
||||
following text: 'Build after other projects are built'.
|
||||
|
||||
Set up a trigger so that when some other projects finish building, a new
|
||||
build is scheduled for this project. This is convenient for running an
|
||||
extensive test after a build is complete, for example.
|
||||
|
||||
This configuration complements the "Build other projects" section in the
|
||||
"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 result: Build results to monitor for between the following
|
||||
options: success, unstable and failure. (default 'success').
|
||||
|
||||
Example:
|
||||
|
||||
.. literalinclude:: /../../tests/triggers/fixtures/reverse.yaml
|
||||
"""
|
||||
reserveBuildTrigger = XML.SubElement(
|
||||
xml_parent, 'jenkins.triggers.ReverseBuildTrigger')
|
||||
|
||||
supported_thresholds = ['SUCCESS', 'UNSTABLE', 'FAILURE']
|
||||
|
||||
XML.SubElement(reserveBuildTrigger, 'spec').text = ''
|
||||
XML.SubElement(reserveBuildTrigger, 'upstreamProjects').text = \
|
||||
data.get('jobs')
|
||||
|
||||
threshold = XML.SubElement(reserveBuildTrigger, 'threshold')
|
||||
result = data.get('result').upper()
|
||||
if result not in supported_thresholds:
|
||||
raise jenkins_jobs.errors.JenkinsJobsException(
|
||||
"Choice should be one of the following options: %s." %
|
||||
", ".join(supported_thresholds))
|
||||
XML.SubElement(threshold, 'name').text = \
|
||||
hudson_model.THRESHOLDS[result]['name']
|
||||
XML.SubElement(threshold, 'ordinal').text = \
|
||||
hudson_model.THRESHOLDS[result]['ordinal']
|
||||
XML.SubElement(threshold, 'color').text = \
|
||||
hudson_model.THRESHOLDS[result]['color']
|
||||
XML.SubElement(threshold, 'completeBuild').text = \
|
||||
str(hudson_model.THRESHOLDS[result]['complete']).lower()
|
||||
|
||||
|
||||
def script(parser, xml_parent, data):
|
||||
"""yaml: script
|
||||
Triggers the job using shell or batch script.
|
||||
|
@ -174,6 +174,7 @@ jenkins_jobs.triggers =
|
||||
github=jenkins_jobs.modules.triggers:github
|
||||
github-pull-request=jenkins_jobs.modules.triggers:github_pull_request
|
||||
pollscm=jenkins_jobs.modules.triggers:pollscm
|
||||
reverse=jenkins_jobs.modules.triggers:reverse
|
||||
script=jenkins_jobs.modules.triggers:script
|
||||
timed=jenkins_jobs.modules.triggers:timed
|
||||
jenkins_jobs.wrappers =
|
||||
|
15
tests/triggers/fixtures/reverse.xml
Normal file
15
tests/triggers/fixtures/reverse.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<triggers class="vector">
|
||||
<jenkins.triggers.ReverseBuildTrigger>
|
||||
<spec/>
|
||||
<upstreamProjects>Fantastic-job</upstreamProjects>
|
||||
<threshold>
|
||||
<name>FAILURE</name>
|
||||
<ordinal>2</ordinal>
|
||||
<color>RED</color>
|
||||
<completeBuild>true</completeBuild>
|
||||
</threshold>
|
||||
</jenkins.triggers.ReverseBuildTrigger>
|
||||
</triggers>
|
||||
</project>
|
4
tests/triggers/fixtures/reverse.yaml
Normal file
4
tests/triggers/fixtures/reverse.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
triggers:
|
||||
- reverse:
|
||||
jobs: 'Fantastic-job'
|
||||
result: 'failure'
|
Loading…
Reference in New Issue
Block a user