Created
February 6, 2012 16:36
-
-
Save scottsbaldwin/1753163 to your computer and use it in GitHub Desktop.
Go Pipeline Cause - Simplified (no materials check)
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
# Based on feedback from the Go development team: | |
# url = "#{ENV['GO_SERVER_URL']}pipelines/#{ENV['GO_PIPELINE_NAME']}/#{ENV['GO_PIPELINE_COUNTER']}/#{ENV['GO_STAGE_NAME']}/#{ENV['GO_STAGE_COUNTER']}.xml" | |
# and lookup //approvedBy/text() | |
require 'rexml/document' | |
require 'net/http' | |
require 'time' | |
include REXML | |
if ARGV.length < 4 | |
puts "USAGE: ruby pipelinecause-simple.rb [pipeline_name] [pipeline_counter] [stage_name] [stage_counter]" | |
exit | |
end | |
user = "YOUR_USERNAME" | |
password = "YOUR_PASSWORD" | |
hostname = "YOUR_GO_HOSTNAME" | |
pipeline_name = ARGV[0] | |
pipeline_counter = ARGV[1] | |
stage_name = ARGV[2] | |
stage_counter = ARGV[3] | |
def get_xml_from_url(url, user, password) | |
uri = URI(url) | |
request = Net::HTTP::Get.new(uri.request_uri) | |
request.basic_auth user, password | |
response = Net::HTTP.start(uri.host, uri.port) do |http| | |
http.request(request) | |
end | |
xml_doc = nil | |
case response | |
when Net::HTTPSuccess then | |
xml_doc = Document.new(response.body) | |
when Net::HTTPRedirection then | |
puts "Redirecting to: #{response['location']}" | |
xml_doc = get_xml_from_url(response['location'], user, password) | |
else | |
puts "I don't know what to do here!" | |
puts response | |
end | |
xml_doc | |
end | |
stages_url = "http://#{hostname}:8153/go/pipelines/#{pipeline_name}/#{pipeline_counter}/#{stage_name}/#{stage_counter}.xml" | |
stages_doc = get_xml_from_url stages_url, user, password | |
approved_by = XPath.first(stages_doc, "//approvedBy/text()") | |
pipeline_label_node = XPath.first(stages_doc, "//pipeline") | |
pipeline_label = pipeline_label_node.attributes["label"] | |
updated_time = XPath.first(stages_doc, "//updated/text()") | |
puts "Pipeline: #{pipeline_name}" | |
puts "Label: #{pipeline_label}" | |
puts "Build Cause: #{approved_by.to_s}" | |
puts "Updated Time: #{Time.parse(updated_time.to_s)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment