[Buildbot-devel] Add a property for WithProperties

Aurelien Bompard aurelien at bompard.org
Fri Sep 24 22:00:09 UTC 2010


> How do I make the variable available (adding it to
> buildbot.process.properties.Properties?) Am I trying to modify an
> immutable?  Or, just needing to make a custom step?

I had a similar problem, and I wrote a custom step, which is rather generic. 
You give it a dictionnary of properties, and it sets them as build 
properties :

---8<-------8<--------8<---------8<---------8<---------8<---------8<--------
class SetProperties(BuildStep):
    name = "setprop"

    def __init__(self, properties={}, **kwargs):
        self.properties = properties
        BuildStep.__init__(self, **kwargs)
        self.addFactoryArguments(properties=properties)
        self.property_changes = properties

    def getRealValue(self, value):
        if isinstance(value, WithProperties):
            return self.build.getProperties().render(value)
        if callable(value):
            return value(self)
        return value

    def start(self):
        self.step_status.setText(self.describe(False))
        for prop, value in self.properties.iteritems():
            value = self.getRealValue(value)
            LOGGER.msg("<SetProperties>: setting %s to %s" % (prop, value))
            self.setProperty(prop, value, "SetProperties")
        self.step_status.setText(self.describe(False))
        self.finished(SUCCESS)

    def describe(self, done=False):
        description = []
        for prop, value in self.properties.iteritems():
            value = self.getRealValue(value)
            description.append("%s = %s" % (prop, value))
        if not description:
            description = BuildStep.describe(self, done)
        return description

    def createSummary(self, log):
        props_set = [ "%s: %r" % (k,v) for k,v in
					  self.property_changes.items() ]
        self.addCompleteLog('property changes', "\n".join(props_set))
---8<-------8<--------8<---------8<---------8<---------8<---------8<--------

I'm using it this way :
bf.addStep(SetProperties(
	properties={"module": WithProperties("%(project)s")}
))

It makes a copy of the "project" property in the new "module" property. In 
your case I'd do:
bf.addStep(SetProperties(properties={
	"bare_branch": os.path.basename(WithProperties("%(branch)s"))
}))

Then, the bare_branch property would be available to the other buildsteps.

It works well for me, but if someone has a better idea (or spots bugs), I'm 
obviously interested :)


Aurélien
-- 
http://aurelien.bompard.org  ~~~~  Jabber : abompard at jabber.fr
"Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning." -- Rick Cook




More information about the devel mailing list