[Buildbot-devel] modifying builder environment at time of build
robert dugal
rmdugal at hotmail.com
Wed Sep 1 17:04:58 UTC 2010
I'm trying to figure out if it's possible to set environment variables from properties during the build.
When a user forces a build I would like to be able to convert some properties entered on the web page into environment variables, so they can alter the make process.
For example, I could enter a property DEBUG with value = 1 and I'd like that to get into the environment so that the build of the source is a debug build.
Our source makefiles support a number of optional build parameters that I would like to be able to support through buildbot.
Different projects support different options so I was hoping to come up with a simple class that would allow projects to define their own set of supported properties.
Alternatively I might just make the class convert every build property into an environment variable.
Here is what I've been prototyping so far:
class PropsToEnv(LoggingBuildStep):
"""
Class to create environment variables from properties
"""
name = "Set Environment From Properties "
description = [name]
descriptionDone = [name]
default_props_list = ['DEBUG','TEST_OPTIONS' ] # this is the default list of props to convert to env
props_list = []
def __init__(self, props_list=default_props_list, **kwargs):
self.props_list = props_list
LoggingBuildStep.__init__(self, **kwargs)
self.addFactoryArguments(props_list=props_list)
def start(self):
count = 0
env_changes=[]
debug_log = []
slaveEnv = self.build.slaveEnvironment
properties = self.build.getProperties()
for p in self.props_list:
debug_log.append("1. Looking for %s in build properties\n" % p)
if p in properties:
debug_log.append("2. Found %s in build properties\n" % p)
if slaveEnv.has_key(p):
debug_log.append("3. %s already exists in environment, not adding\n" % p)
if not slaveEnv.has_key(p):
debug_log.append("3. %s not found in environment, adding\n" % p)
env_changes.append("%s " % p)
env_changes.append("= %s \n" % properties[p])
new_env={p:properties[p]}
slaveEnv.update(new_env)
count = count + 1
self.addCompleteLog('Debug Info', "".join(debug_log))
self.addCompleteLog('Environment Changes ', "".join(env_changes))
self.step_status.setText(['%d environment variables created' % count])
self.finished(SUCCESS)
return SUCCESS
What I've done so far works except that any properties I set into the environment become permanent for that builder.
The next time I try to re-run that builder it still has all the environment variables I previously added.
So if I just did a DEBUG build, the next build becomes DEBUG too, even if I didn't define DEBUG=1 in the force build properties.
More information about the devel
mailing list