Created
May 25, 2011 21:06
-
-
Save mmrobins/991983 to your computer and use it in GitHub Desktop.
Jenkins Lava Lamp Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'uri' | |
require 'rubygems' | |
require 'atom' | |
# Light lava lamps based on Jenkins build status RSS feed | |
# Green lamp lights if all builds are good; | |
# Red lamp lights if any build fails. | |
# | |
# Requires atom gem and bottlerocket X10 control software to be installed. | |
# | |
class JenkinsLava | |
def initialize | |
@BOTTLE_ROCKET_COMMAND="/usr/local/bin/br -x /dev/tty.usbserial" | |
@GREEN_LAMP='1' # codes set on X10 lamp moduels | |
@RED_LAMP='2' | |
end | |
def parse_args | |
@FEED_URL = https://jenkins.puppetlabs.com/view/Known%20Good/rssLatest | |
end | |
def get_rss_feed(feed) | |
data = `curl #{feed} 2> /dev/null` | |
Atom::Feed.new(data) | |
end | |
def parse_rss_feed(feed_data) | |
feed_data.entries.map do |entry| | |
entry.title =~ /(.+)\s+#\w+\s\(([\w ]+)\)/ | |
{$1 => $2} | |
end.inject(&:merge) | |
end | |
def get_failed_builds(build_data) | |
build_data.select {|name, status| status.include? 'broken'}.map(&:first) | |
end | |
def lava_lamp(status, lamp) | |
system "#{@BOTTLE_ROCKET_COMMAND} --#{status}=#{lamp}" | |
end | |
def light_green_lamp | |
lava_lamp("on", @GREEN_LAMP) | |
lava_lamp("off", @RED_LAMP) | |
end | |
def light_red_lamp | |
lava_lamp("on", @RED_LAMP) | |
lava_lamp("off", @GREEN_LAMP) | |
end | |
def light_lava_lamp(failed_builds) | |
if failed_builds.empty? | |
puts "No failed builds- lamp is green." | |
light_green_lamp | |
else | |
puts "Failed builds- lamp is red:" | |
failed_builds.each do |name| | |
puts "\t#{name}" | |
end | |
light_red_lamp | |
end | |
end | |
def main | |
parse_args | |
feed_data = get_rss_feed(@FEED_URL) | |
build_data = parse_rss_feed(feed_data) | |
failed_builds = get_failed_builds(build_data) | |
light_lava_lamp(failed_builds) | |
end | |
end | |
if $0 == __FILE__ | |
JenkinsLava.new.main | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, I am trying to configure build lights in jenkins. Can you please tell me how this script will be executed. I am working on a windows machine.