[Buildbot-devel] Export build logs

Richard Offer richard at whitequeen.com
Thu Dec 27 16:46:18 UTC 2012


I've seen this asked on the list before, and needed something myself.

It would be nice to have a real API/tool to export all the logs for the given build (and any sub builds) as a zip file of nice looking HTML pages, but since that was more than I wanted to spend time on (wget in mirror mode wasn't doing what I wanted), here's my hacked up version using the JSON API.


I call the script as the last build step in the last (triggered) factory - with two arguments the directory to write the results into (will overwite existing files so the directory should be build specific) and the build number. BUILDBOT_HOST and PLAN could be prompted, but I hardcode them...


I don't pretend this is anything other than a hours hack, but it met my immediate needs.


Works with 0.8.6p1, with SVN and tested with both forced and CI triggered builds.




richard




8<---------

#! /usr/bin/python

import json
import sys
import urllib
import urlparse

url = 'http://BUILDBOT_HOST/json/builders/PLAN/builds/%s' % ( sys.argv[2] )
j = json.load(urllib.urlopen(url))

index = open(sys.argv[1] + "/index.html", "w")

index.write( "<html>" )
index.write( "<head>" )
index.write( "</head>" )
index.write( "<body>" )

index.write( "<h1>Log Summary for " + str(j["number"]) + "</h1>" )

index.write( "<h2>Reason: " + j["reason"] + "</h2>" )

if "sourceStamp" in j :


    if j["sourceStamp"]["revision"] != "":
        index.write( "<h3>Source: " + j["sourceStamp"]["repository"] + "</h3>" )
        index.write( "<h3>Revision: " + j["sourceStamp"]["revision"] + "</h3>" )

        for c in j["sourceStamp"]["changes"]:

            index.write( "<h3>Comments:</h3>" )
            index.write( "<tt>" + c["comments"] + "</tt><br/>" )

            index.write( "<h3>Files:</h3>" )
            for f in c["files"]:
                index.write( "<tt>" + f["name"] + "</tt><br />" )
    else:
        index.write( "<h3>Source: " + j["sourceStamp"]["branch"] + "</h3>" )
        index.write( "<h3>Revision: -NOT KNOWN YET- (check SVN step log)</h3>" )

index.write( "<p><table border=\"1\" valign=\"top\">" )
for s in j["steps"]:

    for u in s["urls"]:


        uri = s["urls"][u]

        juri = uri.replace("/builders/", "/json/builders/")

        jstep = json.load( urllib.urlopen(juri) )

        index.write("<tr><td>" +  jstep["builderName"] + "</td><td>" )

        i = 0

        for l in jstep["logs"]:

            href = jstep["builderName"] + "-" + str(i) + ".html"
            index.write( "<a href=\"" + href + "\">" + l[1] + "</a><br />" )
            urllib.urlretrieve( l[1], sys.argv[1] + "/" + href)

            i = i + 1

        index.write( "</td></tr>")

index.write("</table>")

index.write( "</body>" )
index.write( "</html>" )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://buildbot.net/pipermail/devel/attachments/20121227/515a9c27/attachment.html>


More information about the devel mailing list