lib/kraken-build/jenkins-api.rb in kraken-build-0.0.3 vs lib/kraken-build/jenkins-api.rb in kraken-build-0.0.4

- old
+ new

@@ -1,18 +1,25 @@ class JenkinsApi include HTTParty + attr_accessor :skip_plugins + def initialize(options = {}) if options[:port] self.class.base_uri "#{options[:host]}:#{options[:port]}" else self.class.base_uri options[:host] end - if(options[:username] && options[:password]) + if (options[:username] && options[:password]) self.class.basic_auth options[:username] , options[:password] end + if (options[:skip_plugins]) + self.skip_plugins = options[:skip_plugins] + else + self.skip_plugins = [] + end end def get_jobs(options = {}) response = self.class.get("/api/json/", options) jobs = response["jobs"] @@ -32,9 +39,17 @@ def create_job_configuration(repo, branch) draft = get_job_configuration("#{repo}.master") doc = REXML::Document.new(draft) REXML::XPath.first(doc, '//branches//hudson.plugins.git.BranchSpec//name').text = branch + + plugin_names = self.skip_plugins.map { |n| "hudson.plugins.#{n}" } + publishers = REXML::XPath.first(doc, '//project/publishers') + if publishers && publishers.has_elements? && self.skip_plugins && !(self.skip_plugins.empty?) + publishers.children.select { |child| child.xpath.match %r[/hudson\.plugins] }.each do |plugin| + doc.delete_element(plugin.xpath) if plugin_names.any? { |name| plugin.xpath[name]} + end + end doc.to_s end def get_job_configuration(job, options = {})