Skip to content

Instantly share code, notes, and snippets.

@atoulme
Created April 9, 2011 01:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atoulme/911001 to your computer and use it in GitHub Desktop.
Save atoulme/911001 to your computer and use it in GitHub Desktop.
A simple script to grab the info about the last build on jenkins/hudson, take apart the XML and expose it as a Ruby object
require 'uri'
require 'net/http'
require 'rexml/document'
class BuildInfo
def self.getLastBuildInfo(server, job_name, username, password)
resp = nil
Net::HTTP.start(server) {|http|
req = Net::HTTP::Get.new("/job/#{job_name}/lastBuild/api/xml")
req.basic_auth username, password
resp = http.request(req)
}
BuildInfo.new(resp.body)
end
attr_accessor :xml
attr_reader :name, :result, :changes
def initialize(xml)
@xml = xml
parsed = REXML::Document.new(xml)
@name = parsed.elements['//fullDisplayName/text()']
@result = parsed.elements['//result/text()']
@changes = parsed.elements.to_a('//item').collect {|item| "#{item.elements['id/text()']}\t#{item.elements['author/fullName/text()']}\t#{item.elements['date/text()']}\n#{item.elements['comment/text()']}" }
end
def formatInfo
"* #{name} : #{result}\n#{changes.empty? ? "" : "** "}#{changes.join("** ")}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment