Re: Last Build Status
Paul Willworth <[email protected]> Thu, 22 Sep 2011 09:43:25 -0700
| Newsgroups | gmane.comp.java.cruise-control.user |
|---|---|
| Message-ID | <[email protected]> |
I wrote this python script to calculate the time to fix the build. Thought I'd share incase anyone else can use it.
#!/usr/bin/python
# This script is meant to be used with the Cruise Control RSS feed for a project.
# If the build label given is a successful build and has at least 1 failed build
# immediately prior to it, the script returns the number of minutes since the
# build last became broken to the time of this successful build.
import sys
from optparse import OptionParser
from xml.dom import minidom
import urllib
from datetime import timedelta, datetime
parser = OptionParser("usage: %prog projectName buildLabel")
(options, args) = parser.parse_args()
projectName = args[0]
buildLabel = args[1]
cruiseFeedTemplate = "http://buildserver:8080/cruisecontrol/rss/{0}"
# utility function for getting text out of xml element child nodes
def getText(nodelist):
rc = []
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
# parse xml dom for build times
def getTimeToFix(builds):
buildStatus = ""
buildTime = ""
failTime = ""
items = builds.getElementsByTagName("item")
for item in items:
# get the important bits of info from this build attempt
title = getText(item.getElementsByTagName("title")[0].childNodes)
itemTime = title[:title.find(",")].strip()
itemStatus = title[title.find(",")+1:].strip()
link = getText(item.getElementsByTagName("link")[0].childNodes)
itemLabel = link[link.find("?")+23:]
# See if this is the build we are looking for
if itemLabel == buildLabel and buildStatus == "":
buildStatus = itemStatus
# bail if build is failed
if itemStatus != 'passed':
break
else:
buildTime = itemTime
continue
# look for prior build info after this build found
if buildStatus == 'passed':
if itemStatus != 'passed':
failTime = itemTime
else:
break
# debugging
print "buildStatus: {0} buildTime: {1} failTime: {2}".format(buildStatus, buildTime, failTime)
# Return the minutes to fix or 0 if not a fixing build
if buildTime != "" and failTime != "":
timeToFix = datetime.strptime(buildTime, "%a %b %d %H:%M:%S %Z %Y") - datetime.strptime(failTime, "%a %b %d %H:%M:%S %Z %Y")
return (timeToFix.seconds/60)+1
else:
return 0
# Get the project RSS feed
domp = None
try:
f = urllib.urlopen(cruiseFeedTemplate.format(projectName))
domp = minidom.parse(f)
except Exception as e:
print "Failed to get feed:", e
# Get and print the time to fix this build or zero if build was not broken
if domp != None:
print "Minutes to fix: {0}\n".format(getTimeToFix(domp))
-Paul
________________________________
From: Julian Simpson [mailto:[email protected]]
Sent: Wednesday, September 14, 2011 1:22 PM
To: [email protected]
Subject: Re: [Cruisecontrol-user] Last Build Status
I'd probably write a script to work on the XML feed.
J.
On Wednesday, 14 September 2011, Paul Willworth wrote:
I am trying to figure out a way to measure time taken to fix a broken build. I'm thinking I would need a way to check the status of the last build, and trigger a calculation of the time if the current build is successful. As far as I can tell though, there are only handy properties available to tell you when the last successful build was, not what the last build was. Has anyone found a good way to calculate this metric?
Paul Willworth
--
Julian Simpson
The Build Doctor Ltd.
http://www.build-doctor.com
[email protected]<mailto:[email protected]>
(+44) 207 183 0323
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Cruisecontrol-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cruisecontrol-user