arvidr
arvidr

Reputation: 53

Is it possible to let a triggered builder return a value to the parent builder in Buildbot?

I have a setup where a top-level builder triggers one Mac builder and one Windows builder to do the actual building. However, if both succeed I want to aggregate and promote the binaries they produced in our binary repository, handled by Artifactory. However, to do so, the top-level builder need to know the build numbers of the triggered builders. How can I communicate this information back to the top-level builder?

Upvotes: 2

Views: 119

Answers (1)

arvidr
arvidr

Reputation: 53

I figured it out myself. This is what I like about Buildbot actually, you can always extend it to fit your needs. I ended up extending the Trigger build step to also set a property with the information I needed, like this:

class TriggerSetProperties(Trigger):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.triggeredBuilds = {}

    @defer.inlineCallbacks
    def addBuildUrls(self, rclist):
        yield super().addBuildUrls(rclist)
        
        ## This is just a duplicate of the parent function
        ## used to get the builder name and number of the triggered builds
        brids = {}
        for was_cb, results in rclist:
            if isinstance(results, tuple):
                results, brids = results
            builderNames = {}
            if was_cb:  # errors were already logged in worstStatus
                for builderid, br in brids.items():
                    builds = yield self.master.db.builds.getBuilds(buildrequestid=br)
                    for build in builds:
                        builderid = build['builderid']
                        # When virtual builders are used, the builderid used for triggering
                        # is not the same as the one that the build actually got
                        if builderid not in builderNames:
                            builderDict = yield self.master.data.get(("builders", builderid))
                            builderNames[builderid] = builderDict["name"]
                       
                        self.triggeredBuilds[builderNames[builderid]] = build['number']

        properties = self.build.getProperties()
        properties.setProperty(
            "TriggeredBuilds", self.triggeredBuilds, self.name, runtime=True)

Upvotes: 2

Related Questions