Skip to content

Commit

Permalink
allow properties in IRC force builds
Browse files Browse the repository at this point in the history
This adds a `--props=` option with the same syntax as
the `buildbot try --properties=` option to specify a
list of properties for the build that is forced.
  • Loading branch information
dzhurley committed Aug 26, 2011
1 parent 18453e1 commit 14d6847
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
4 changes: 4 additions & 0 deletions master/buildbot/scripts/runner.py
Expand Up @@ -938,6 +938,10 @@ class ForceOptions(OptionsWithOptionsFile):
["branch", None, None, "which branch to build"],
["revision", None, None, "which revision to build"],
["reason", None, None, "the reason for starting the build"],
["props", None, None,
"A set of properties made available in the build environment, "
"format is --properties=prop1=value1,prop2=value2,.. "
"option can be specified multiple times."],
]

def parseArgs(self, *args):
Expand Down
34 changes: 30 additions & 4 deletions master/buildbot/status/words.py
Expand Up @@ -33,6 +33,7 @@
from buildbot.status import base
from buildbot.status.results import SUCCESS, WARNINGS, FAILURE, EXCEPTION, RETRY
from buildbot.scripts.runner import ForceOptions
from buildbot.process.properties import Properties

# twisted.internet.ssl requires PyOpenSSL, so be resilient if it's missing
try:
Expand Down Expand Up @@ -461,7 +462,7 @@ def watchedBuildFinished(self, b):
self.send("Build details are at %s" % buildurl)

def command_FORCE(self, args, who):
errReply = "try 'force build [--branch=BRANCH] [--revision=REVISION] <WHICH> <REASON>'"
errReply = "try 'force build [--branch=BRANCH] [--revision=REVISION] [--props=PROP1=VAL1,PROP2=VAL2...] <WHICH> <REASON>'"
args = shlex.split(args)
if not args:
raise UsageError(errReply)
Expand All @@ -475,13 +476,16 @@ def command_FORCE(self, args, who):
branch = opts['branch']
revision = opts['revision']
reason = opts['reason']
props = opts['props']

if which is None:
raise UsageError("you must provide a Builder, " + errReply)

# keep weird stuff out of the branch and revision strings.
# keep weird stuff out of the branch, revision, and properties args.
branch_validate = self.master.config.validation['branch']
revision_validate = self.master.config.validation['revision']
pname_validate = self.master.config.validation['property_name']
pval_validate = self.master.config.validation['property_value']
if branch and not branch_validate.match(branch):
log.msg("bad branch '%s'" % branch)
self.send("sorry, bad branch '%s'" % branch)
Expand All @@ -491,19 +495,41 @@ def command_FORCE(self, args, who):
self.send("sorry, bad revision '%s'" % revision)
return

properties = None
if props:
# split props into name:value dict
pdict = {}
propertylist = props.split(",")
for i in range(0,len(propertylist)):
splitproperty = propertylist[i].split("=", 1)
pdict[splitproperty[0]] = splitproperty[1]

# set properties
properties = Properties()
for prop in pdict:
pname = prop
pvalue = pdict[prop]
if not pname_validate.match(pname) \
or not pval_validate.match(pvalue):
log.msg("bad property name='%s', value='%s'" % (pname, pvalue))
self.send("sorry, bad property name='%s', value='%s'" %
(pname, pvalue))
return
properties.setProperty(pname, pvalue, "Force Build IRC")

bc = self.getControl(which)

reason = "forced: by %s: %s" % (self.describeUser(who), reason)
ss = SourceStamp(branch=branch, revision=revision)
d = bc.submitBuildRequest(ss, reason)
d = bc.submitBuildRequest(ss, reason, props=properties.asDict())
def subscribe(buildreq):
ireq = IrcBuildRequest(self, self.useRevisions)
buildreq.subscribe(ireq.started)
d.addCallback(subscribe)
d.addErrback(log.err, "while forcing a build")


command_FORCE.usage = "force build [--branch=branch] [--revision=revision] <which> <reason> - Force a build"
command_FORCE.usage = "force build [--branch=branch] [--revision=revision] [--props=prop1=val1,prop2=val2...] <which> <reason> - Force a build"

def command_STOP(self, args, who):
args = shlex.split(args)
Expand Down
5 changes: 3 additions & 2 deletions master/docs/manual/cfg-statustargets.rst
Expand Up @@ -1184,12 +1184,13 @@ as shown in the example earlier.
If the ``allowForce=True`` option was used, some addtional commands
will be available:

:samp:`force build [--branch={BRANCH}] [--revision={REVISION}] {BUILDER} {REASON}`
:samp:`force build [--branch={BRANCH}] [--revision={REVISION}] [--props=PROP1=VAL1,PROP2=VAL2...] {BUILDER} {REASON}`
Tell the given :class:`Builder` to start a build of the latest code. The user
requesting the build and *REASON* are recorded in the :class:`Build` status. The
buildbot will announce the build's status when it finishes.The
user can specify a branch and/or revision with the optional
parameters :samp:`--branch={BRANCH}` and :samp:`--revision={REVISION}`.
parameters :samp:`--branch={BRANCH}` and :samp:`--revision={REVISION}`. The user
can also give a list of properties with :samp:`--props={PROP1=VAL1,PROP2=VAL2..}`.


:samp:`stop build {BUILDER} {REASON}`
Expand Down

0 comments on commit 14d6847

Please sign in to comment.