This buildstep is similar to ShellCommand, except that it captures the output of the command into a property. It is usually used like this:
from buildbot.steps import shell
f.addStep(shell.SetProperty(command="uname -a", property="uname"))
This runs uname -a and captures its output (including stderr), stripped
of leading and trailing whitespace, in the property "uname". To avoid
stripping, add strip=False.
The property argument can be specified as a WithProperties
object, allowing the property name to be built from other property values.
The more advanced usage allows you to specify a function to extract properties
from the command output. Here you can use regular expressions, string
interpolation, or whatever you would like. In this form, extract_fn
should be passed, and not property. The extract_fn function is
called with three arguments: the exit status of the command, its standard
output as a string, and its standard error as a string. It should return a
dictionary containing all new properties.
def glob2list(rc, stdout, stderr):
jpgs = [ l.strip() for l in stdout.split('\n') ]
return { 'jpgs' : jpgs }
f.addStep(SetProperty(command="ls -1 *.jpg", extract_fn=glob2list))
Note that any ordering relationship of the contents of stdout and stderr is lost. For example, given
f.addStep(SetProperty(
command="echo output1; echo error >&2; echo output2",
extract_fn=my_extract))
Then my_extract will see stdout="output1\noutput2\n"
and stderr="error\n".
See also Setting Properties.