Skip to content

Instantly share code, notes, and snippets.

@jshiell
Created May 18, 2012 14:29
Show Gist options
  • Save jshiell/2725544 to your computer and use it in GitHub Desktop.
Save jshiell/2725544 to your computer and use it in GitHub Desktop.
Get status from a TeamCity server.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
def get_teamcity_status(server_host)
doc = Nokogiri::HTML(open("http://#{server_host}/externalStatus.html"))
build_count = doc.css('table.tcTable').size
failure_count = 0
fatal_count = doc.css('span.teamCityErrorMessage').size
all_looked_at = true
builds = []
doc.css('table.tcTable').each do |table|
group_name = table.css('a.buildTypeName')[0].content
table.css('td.buildConfigurationName').each do |build_element|
build = {}
build[:group] = group_name
build[:name] = build_element.css('a')[0].content
build_image_alt = build_element.css('img').attr('alt').to_s.downcase
if build_image_alt =~ /responsible/ || build_image_alt =~ /investigating/ || build_image_alt =~ /fixed/
build[:status] = :responsible
elsif build_image_alt =~ /fail/
build[:status] = :fail
else
build[:status] = :success
end
builds << build
end
end
builds
end
if ARGV.length == 0
puts "Usage: #{__FILE__} <server>"
exit 1
end
server = ARGV[0]
build_status = get_teamcity_status(server)
puts "Status for #{server}:"
puts " Failed: #{build_status.find_all{|build| build[:status] == :fail}.size}"
puts " Responsible: #{build_status.find_all{|build| build[:status] == :responsible}.size}"
puts " Success: #{build_status.find_all{|build| build[:status] == :success}.size}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment