Permalink
Browse files

adding inline xml config editing with nokogiri

  • Loading branch information...
1 parent 7c96adf commit e8449f323329ac189dd095cacfa365bc494fee69 @pxlpnk committed Jul 9, 2012
Showing with 23 additions and 8 deletions.
  1. +7 −6 lib/kraken-build.rb
  2. +16 −2 lib/kraken-build/jenkins-api.rb
View
13 lib/kraken-build.rb
@@ -1,5 +1,6 @@
require "HTTParty"
require "awesome_print"
+require 'nokogiri'
require "kraken-build/version"
require "kraken-build/jenkins-api.rb"
@@ -33,12 +34,12 @@ def self.run
@branches = get_github_branches
create = compute_jobs_to_create
- create.map do |job|
- job_name = "#{@repository}.#{job}"
- puts "creating => #{job_name}"
- # @jenkins.create_job(job_name,"")
- # @jenkins.build_job(job_name)
- end
+ create.map do |job|
+ job_name = "#{@repository}.#{job}"
+ puts "creating => #{job_name}"
+ @jenkins.create_job(job_name)
+ @jenkins.build_job(job_name)
+ end
remove = compute_jobs_to_remove
View
18 lib/kraken-build/jenkins-api.rb
@@ -24,12 +24,26 @@ def get_jobs(options = {})
jobs.map{|job| job["name"]}
end
- def create_job(job_name, job_config, options = {})
+ def create_job(job, options = {})
+ repo = job.split('.').first
+ branch_name = job.split('.').last
+ job_config = create_job_configuration(repo, branch_name)
options.merge!(
:body => job_config,
:format => :xml, :headers => { 'content-type' => 'application/xml' })
- self.class.post("/createItem/api/xml?name=#{CGI.escape(job_name)}", options)
+ self.class.post("/createItem/api/xml?name=#{CGI.escape(job)}", options)
+ end
+
+ def create_job_configuration(repo, branch)
+
+ draft = get_job_configuration("#{repo}.master")
+
+ doc = Nokogiri.XML(draft)
+
+ doc.xpath('//branches//hudson.plugins.git.BranchSpec//name').first.content = "#{repo}.#{branch}"
+
+ doc.to_xml
end
def get_job_configuration(job, options = {})

0 comments on commit e8449f3

Please sign in to comment.