Skip to content

Instantly share code, notes, and snippets.

@Jc2k
Created May 28, 2012 15:37
Show Gist options
  • Save Jc2k/2819772 to your computer and use it in GitHub Desktop.
Save Jc2k/2819772 to your computer and use it in GitHub Desktop.
Getting a successful build number into another build using renderables
class LastBuild(util.ComparableMixin):
"""
This code isn't meant to be functional!
It's really pseudo code for how i would the # of the last successful
build into a completely unrelated build - some digging around will
be required.
You are invited to explore the build.master API and see if there is
a better way to iterate previous builds - look for getLastFinishedBuild.
That object will have a getPreviousBuild which will let you walk
builds looking for a success.
"""
implements(IRenderable)
def __init__(self, buildername, subst='%s'):
self.buildername = buildername
self.subst = subst
def getRenderingFor(self, props):
build = props.getBuild()
builder_status = build.master.getBuilder(self.buildername)
for num in xrange(1,40):
b = builder_status.getBuild(-num)
if not b:
continue
if b.getResults() == SUCCESS:
return self.subst % str(b.number)
return "OH WELL"
# In your .cfg, you might use it like this:
ShellCommand(
command = ['cp', LastBuild('buildername', "somedir/%s/tarball.tar.gz")],
)
class MyShellCommand(ShellCommand):
def find_finished_build(self, buildername):
builder_status = self.master.getBuilder(buildername)
for num in xrange(1,40):
b = builder_status.getBuild(-num)
if not b:
continue
if b.getResults() == SUCCESS:
return str(b.number)
return "OH WELL"
def start(self):
self.setCommand(["cp", "/blah/%s/blah.tar.gz" % self.find_finished_build("myotherbuilder")])
return ShellCommand.start(self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment