1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from buildbot.process.buildstep import LoggingBuildStep, SUCCESS, FAILURE, EXCEPTION
17 from buildbot.process.properties import Properties
18 from buildbot.schedulers.triggerable import Triggerable
19 from twisted.python import log
20 from twisted.internet import defer
21
23 """I trigger a scheduler.Triggerable, to use one or more Builders as if
24 they were a single buildstep (like a subroutine call).
25 """
26 name = "trigger"
27
28 renderables = [ 'set_properties', 'schedulerNames', 'sourceStamp' ]
29
30 flunkOnFailure = True
31
32 - def __init__(self, schedulerNames=[], sourceStamp=None, updateSourceStamp=None, alwaysUseLatest=False,
33 waitForFinish=False, set_properties={}, copy_properties=[], **kwargs):
34 """
35 Trigger the given schedulers when this step is executed.
36
37 @param schedulerNames: A list of scheduler names that should be
38 triggered. Schedulers can be specified using
39 WithProperties, if desired.
40
41 @param sourceStamp: A dict containing the source stamp to use for the
42 build. Keys must include branch, revision, repository and
43 project. In addition, patch_body, patch_level, and
44 patch_subdir can be specified. Only one of
45 sourceStamp, updateSourceStamp and alwaysUseLatest
46 can be specified. Any of these can be specified using
47 WithProperties, if desired.
48
49 @param updateSourceStamp: If True (the default), I will try to give
50 the schedulers an absolute SourceStamp for
51 their builds, so that a HEAD build will use
52 the same revision even if more changes have
53 occurred since my build's update step was
54 run. If False, I will use the original
55 SourceStamp unmodified.
56
57 @param alwaysUseLatest: If False (the default), I will give the
58 SourceStamp of the current build to the
59 schedulers (as controled by updateSourceStamp).
60 If True, I will give the schedulers an empty
61 SourceStamp, corresponding to the latest
62 revision.
63
64 @param waitForFinish: If False (the default), this step will finish
65 as soon as I've started the triggered
66 schedulers. If True, I will wait until all of
67 the triggered schedulers have finished their
68 builds.
69
70 @param set_properties: A dictionary of properties to set for any
71 builds resulting from this trigger. These
72 properties will override properties set in the
73 Triggered scheduler's constructor.
74
75 @param copy_properties: a list of property names to copy verbatim
76 into any builds resulting from this trigger.
77
78 """
79 assert schedulerNames, "You must specify a scheduler to trigger"
80 if sourceStamp and updateSourceStamp:
81 raise ValueError("You can't specify both sourceStamp and updateSourceStamp")
82 if sourceStamp and alwaysUseLatest:
83 raise ValueError("You can't specify both sourceStamp and alwaysUseLatest")
84 if alwaysUseLatest and updateSourceStamp:
85 raise ValueError("You can't specify both alwaysUseLatest and updateSourceStamp")
86 self.schedulerNames = schedulerNames
87 self.sourceStamp = sourceStamp
88 self.updateSourceStamp = updateSourceStamp or not (alwaysUseLatest or sourceStamp)
89 self.alwaysUseLatest = alwaysUseLatest
90 self.waitForFinish = waitForFinish
91 self.set_properties = set_properties
92 self.copy_properties = copy_properties
93 self.running = False
94 self.ended = False
95 LoggingBuildStep.__init__(self, **kwargs)
96 self.addFactoryArguments(schedulerNames=schedulerNames,
97 sourceStamp=sourceStamp,
98 updateSourceStamp=updateSourceStamp,
99 alwaysUseLatest=alwaysUseLatest,
100 waitForFinish=waitForFinish,
101 set_properties=set_properties,
102 copy_properties=copy_properties)
103
108
109 - def end(self, result):
110 if not self.ended:
111 self.ended = True
112 return self.finished(result)
113
179 d.addCallback(start_builds)
180
181 def cb(rclist):
182 rc = SUCCESS
183 for was_cb, results in rclist:
184
185 if not was_cb:
186 rc = EXCEPTION
187 log.err(results)
188 break
189 if results == FAILURE:
190 rc = FAILURE
191 return self.end(rc)
192 def eb(why):
193 return self.end(FAILURE)
194
195 if self.waitForFinish:
196 d.addCallbacks(cb, eb)
197
198 d.addErrback(log.err, '(ignored) while triggering builds:')
199