This page documents the latest, unreleased version of Buildbot. For documentation for released versions, see http://docs.buildbot.net/current/.
Build properties are a generalized way to provide configuration information to build steps; see Build Properties for the conceptual overview of properties.
Some build properties come from external sources and are set before the build begins; others are set during the build, and available for later steps. The sources for properties are:
If the same property is supplied in multiple places, the final appearance takes precedence. For example, a property set in a builder configuration will override one supplied by a scheduler.
Properties are stored internally in JSON format, so they are limited to basic types of data: numbers, strings, lists, and dictionaries.
The following build properties are set when the build is started, and are available to all steps.
This property is set when a Source step checks out the source tree, and provides the revision that was actually obtained from the VC system. In general this should be the same as revision, except for non-absolute sourcestamps, where got_revision indicates what revision was current when the checkout was performed. This can be used to rebuild the same source code later.
For some VC systems (Darcs in particular), the revision is a large string containing newlines, and is not suitable for interpolation into a filename.
For multi-codebase builds (where codebase is not the default ''), this property is a dictionary, keyed by codebase.
For single codebase builds, where the codebase is '', the following Source Stamp Attributes are also available as properties: branch, revision, repository, and project .
branch revision repository project codebase
For details of these attributes see Concepts.
This attribute is a list of dictionaries representing the changes that make up this sourcestamp.
For the most part, properties are used to alter the behavior of build steps during a build. This is done by using renderables (objects implementing the IRenderable interface) as step parameters. When the step is started, each such object is rendered using the current values of the build properties, and the resultant rendering is substituted as the actual value of the step parameter.
Buildbot offers several renderable object types covering common cases. It's also possible to create custom renderables.
Properties are defined while a build is in progress; their values are not available when the configuration file is parsed. This can sometimes confuse newcomers to Buildbot! In particular, the following is a common error:
if Property('release_train') == 'alpha': f.addStep(...)
This does not work because the value of the property is not available when the if statement is executed. However, Python will not detect this as an error - you will just never see the step added to the factory.
You can use renderables in most step parameters. Please file bugs for any parameters which do not accept renderables.
The simplest renderable is Property, which renders to the value of the property named by its argument:
from buildbot.plugins import steps, util f.addStep(steps.ShellCommand(command=['echo', 'buildername:', util.Property('buildername')]))
You can specify a default value by passing a default keyword argument:
f.addStep(steps.ShellCommand(command=['echo', 'warnings:', util.Property('warnings', default='none')]))
The default value is used when the property doesn't exist, or when the value is something Python regards as False. The defaultWhenFalse argument can be set to False to force buildbot to use the default argument only if the parameter is not set:
f.addStep(steps.ShellCommand(command=['echo', 'warnings:', util.Property('warnings', default='none', defaultWhenFalse=False)]))
The default value can be a renderable itself, e.g.,
Property can only be used to replace an entire argument: in the example above, it replaces an argument to echo. Often, properties need to be interpolated into strings, instead. The tool for that job is Interpolate.
The more common pattern is to use Python dictionary-style string interpolation by using the %(prop:<propname>)s syntax. In this form, the property name goes in the parentheses, as above. A common mistake is to omit the trailing "s", leading to a rather obscure error from Python ("ValueError: unsupported format character").
from buildbot.plugins import steps, util f.addStep(steps.ShellCommand(command=['make', util.Interpolate('REVISION=%(prop:got_revision)s'), 'dist']))
This example will result in a make command with an argument like REVISION=12098.
The syntax of dictionary-style interpolation is a selector, followed by a colon, followed by a selector specific key, optionally followed by a colon and a string indicating how to interpret the value produced by the key.
The following selectors are supported.
The following ways of interpreting the value are available.
Although these are similar to shell substitutions, no other substitutions are currently supported.
from buildbot.plugins import steps, util f.addStep(steps.ShellCommand(command=['make', util.Interpolate('REVISION=%(prop:got_revision:-%(src::revision:-unknown)s)s'), 'dist']))
In addition, Interpolate supports using positional string interpolation. Here, %s is used as a placeholder, and the substitutions (which may be renderables), are given as subsequent arguments:
Like Python, you can use either positional interpolation or dictionary-style interpolation, not both. Thus you cannot use a string like Interpolate("foo-%(src::revision)s-%s", "branch").
While Interpolate can handle many simple cases, and even some common conditionals, more complex cases are best handled with Python code. The renderer decorator creates a renderable object whose rendering is obtained by calling the decorated function when the step it's passed to begins. The function receives an IProperties object, which it can use to examine the values of any and all properties. For example:
from buildbot.plugins import steps, util @util.renderer def makeCommand(props): command = ['make'] cpus = props.getProperty('CPUs') if cpus: command.extend(['-j', str(cpus+1)]) else: command.extend(['-j', '2']) command.extend(['all']) return command f.addStep(steps.ShellCommand(command=makeCommand))
You can think of renderer as saying "call this function when the step starts".
Transform is an alternative to renderer. While renderer is useful for creating new renderables, Transform is easier to use when you want to transform or combine the renderings of preexisting ones.
Transform takes a function and any number of positional and keyword arguments. The function must either be a callable object or a renderable producing one. When rendered, a Transform first replaces all of its arguments that are renderables with their renderings, then calls the function, passing it the positional and keyword arguments, and returns the result as its own rendering.
For example, suppose my_path is a path on the buildslave, and you want to get it relative to the build directory. You can do it like this:
import os.path from buildbot.plugins import util my_path_rel = util.Transform(os.path.relpath, my_path, start=util.Property('builddir'))
This works whether my_path is an ordinary string or a renderable. my_path_rel will be a renderable in either case, however.
If nested list should be flatten for some renderables, FlattenList could be used. For example:
f.addStep(ShellCommand(command=[ 'make' ], descriptionDone=FlattenList([ 'make ', [ 'done' ]])))
descriptionDone would be set to [ 'make', 'done' ] when the ShellCommand executes. This is useful when a list-returning property is used in renderables.
ShellCommand automatically flattens nested lists in its command argument, so there is no need to use FlattenList for it.
This class is deprecated. It is an older version of Interpolate. It exists for compatibility with older configs.
The simplest use of this class is with positional string interpolation. Here, %s is used as a placeholder, and property names are given as subsequent arguments:
from buildbot.plugins import steps, util f.addStep(steps.ShellCommand( command=["tar", "czf", util.WithProperties("build-%s-%s.tar.gz", "branch", "revision"), "source"]))
If this BuildStep were used in a tree obtained from Git, it would create a tarball with a name like build-master-a7d3a333db708e786edb34b6af646edd8d4d3ad9.tar.gz.
The more common pattern is to use Python dictionary-style string interpolation by using the %(propname)s syntax. In this form, the property name goes in the parentheses, as above. A common mistake is to omit the trailing "s", leading to a rather obscure error from Python ("ValueError: unsupported format character").
from buildbot.plugins import steps, util f.addStep(steps.ShellCommand(command=['make', util.WithProperties('REVISION=%(got_revision)s'), 'dist']))
This example will result in a make command with an argument like REVISION=12098.
The dictionary-style interpolation supports a number of more advanced syntaxes in the parentheses.
Although these are similar to shell substitutions, no other substitutions are currently supported, and replacement in the above cannot contain more substitutions.
Note: like Python, you can use either positional interpolation or dictionary-style interpolation, not both. Thus you cannot use a string like WithProperties("foo-%(revision)s-%s", "branch").
If the options described above are not sufficient, more complex substitutions can be achieved by writing custom renderables.
The IRenderable interface is simple - objects must provide a getRenderingFor method. The method should take one argument - an IProperties provider - and should return the rendered value or a deferred firing with one. Pass instances of the class anywhere other renderables are accepted. For example:
class DetermineFoo(object): implements(IRenderable) def getRenderingFor(self, props): if props.hasProperty('bar'): return props['bar'] elif props.hasProperty('baz'): return props['baz'] return 'qux' ShellCommand(command=['echo', DetermineFoo()])
or, more practically,
class Now(object): implements(IRenderable) def getRenderingFor(self, props): return time.clock() ShellCommand(command=['make', Interpolate('TIME=%(kw:now)s', now=Now())])
This is equivalent to:
@renderer def now(props): return time.clock() ShellCommand(command=['make', Interpolate('TIME=%(kw:now)s', now=now)])
Note that a custom renderable must be instantiated (and its constructor can take whatever arguments you'd like), whereas a function decorated with renderer can be used directly.