Skip to content

Instantly share code, notes, and snippets.

@garrensmith
Created April 11, 2011 12:55
Show Gist options
  • Select an option

  • Save garrensmith/913467 to your computer and use it in GitHub Desktop.

Select an option

Save garrensmith/913467 to your computer and use it in GitHub Desktop.
Creates a new release branch and pushes it upstream, it also updates all the hudson jobs to build this release
require 'rexml/document'
require 'net/http'
require 'uri'
require 'rakefiles/utils'
namespace :release do
@server_url = "http://server_url"
@server_port = "8080"
@unit_tests = "/view/Branch/job/unit_test_job/config.xml"
@integration_tests = "/view/Branch/job/Integration_test_job/config.xml"
@regression_tests = "/view/Branch/job/regression_test_job/config.xml"
desc "Create new release"
task :new, [:release_num] do |t, args|
if (!args.release_num)
raise "Please supply version number"
end
git_create_release(args.release_num)
update_branch(@unit_tests, args.release_num)
update_branch(@integration_tests, args.release_num)
update_branch(@financial_tests, args.release_num)
update_branch(@publish, args.release_num)
update_branch(@publish_to_postdev, args.release_num)
update_branch(@regression_tests, args.release_num)
end
def git_create_release(branch_name)
sh "git checkout -b #{branch_name}"
sh "git push origin #{branch_name}"
end
def update_branch(job, branch_name)
config = get_build_job_config(job)
new_config = set_build_branch(config,branch_name)
save_build_job_config(job,new_config)
end
def set_build_branch(config,branch_name)
doc = REXML::Document.new(config)
doc.elements.each('project/scm/branches/hudson.plugins.git.BranchSpec/name') do |ele|
puts "setting #{ele.text} to #{branch_name}"
ele.text = branch_name
end
return doc.to_s
end
def save_build_job_config(job, config)
request = Net::HTTP::Post.new(job)
request.body = config
Net::HTTP.new(@server_url, @server_port).start{|http| http.request(request)}
end
def get_build_job_config(job_name)
request = Net::HTTP::Get.new("/view/Branch/job/KeyBlade%20-%20Unit%20Tests%20for%20Branch/config.xml")
request['Content-Type'] = "text/xml"
response = Net::HTTP.start(@server_url, @server_port){|http| http.request(request)}
if response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
encoding = response.get_fields("Content-Encoding")
if encoding and encoding.include?("gzip")
return Zlib::GzipReader.new(StringIO.new(response.body)).read
else
return response.body
end
else
puts response
raise APIError, "Error retrieving #{path}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment