Skip to content

Build Status Lamp with Ruby and TeamCity

by Cory Foy on October 3rd, 2008

Recently at work we got our new build status light setup. We’re using TeamCity as our Continuous Integration Server, MSBuild as the build script, and a homemade Ruby Script to control the lamp.

The setup sits in our team room and looks like this:

DSC_1028

The Build Lamp (a red lava lamp in this case) is controlled by an X10 Transceiver:

 

DSC_1030

I have a little X10 transmitter attached to the serial port of the computer you see. It’s basically the setup from the Firecracker kit on X10.com. To check the status, we enabled the status widget feature of TeamCity, and I wrote a simple Ruby script to parse the widget using Why’s awesome Hpricot parser and the CM17A X10 Ruby code from Rubyforge. That script is available for download but is just:

require 'hpricot'require 'open-uri'require 'x10/cm17a'

def there_are_failing_builds()  retry_count = 0  begin    doc = Hpricot(open("http://teamcity:8080/externalStatus.html"))    failingBuildElements = doc.search("//img[@title='Build configuration is failing']")    return (failingBuildElements.length > 0)  rescue    if retry_count < 3      retry_count += 1      puts "Network not available. Sleeping for 10 seconds then retrying"      sleep 10 #Wait for a bit to see if the network will come up      retry    else        puts "Could not open web page (Network is down?)"        return false    end  endend

def turn_on_lamp()  puts "BUILD BROKEN! Turning On Lamp"  #Do it twice because sometimes the first doesn't take  X10.device('C1').on  X10.device('C1').onend

def turn_off_lamp()  #Do it twice because sometimes the first doesn't take  puts "Build A-Ok! Turning off lamp"  X10.device('C1').off  X10.device('C1').offend

puts "Welcome to the Build Monitor"

while(true)	if(there_are_failing_builds())	  turn_on_lamp()	else	  turn_off_lamp()	end	puts "Next status check in 60 seconds..."	sleep 60end

We’ll also play a build break sound (the team has chose the Macarena for now), but sound isn’t working on that machine yet.

Happy hacking!

From → Uncategorized

One Comment

Trackbacks & Pingbacks

  1. Top 5 Build Failure Sounds | Scrumology

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS