Class: JenkinsApi
- Inherits:
-
Object
- Object
- JenkinsApi
- Includes:
- HTTParty
- Defined in:
- lib/kraken-build/jenkins-api.rb
Instance Attribute Summary collapse
-
#skip_plugins ⇒ Object
Returns the value of attribute skip_plugins.
Instance Method Summary collapse
- #build_job(job_name, options = {}) ⇒ Object
- #create_job(job, options = {}) ⇒ Object
- #create_job_configuration(repo, branch) ⇒ Object
- #get_job_configuration(job, options = {}) ⇒ Object
- #get_jobs(options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ JenkinsApi
constructor
A new instance of JenkinsApi.
- #remove_job(job_name, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ JenkinsApi
Returns a new instance of JenkinsApi.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/kraken-build/jenkins-api.rb', line 6 def initialize( = {}) if [:port] self.class.base_uri "#{[:host]}:#{[:port]}" else self.class.base_uri [:host] end if ([:username] && [:password]) self.class.basic_auth [:username] , [:password] end if ([:skip_plugins]) self.skip_plugins = [:skip_plugins] else self.skip_plugins = [] end end |
Instance Attribute Details
#skip_plugins ⇒ Object
Returns the value of attribute skip_plugins.
4 5 6 |
# File 'lib/kraken-build/jenkins-api.rb', line 4 def skip_plugins @skip_plugins end |
Instance Method Details
#build_job(job_name, options = {}) ⇒ Object
66 67 68 |
# File 'lib/kraken-build/jenkins-api.rb', line 66 def build_job(job_name, ={}) self.class.get("/job/#{CGI.escape(job_name)}/build") end |
#create_job(job, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/kraken-build/jenkins-api.rb', line 30 def create_job(job, = {}) repo, branch_name = job.split('.', 2) job_config = create_job_configuration(repo, branch_name) .merge!( :body => job_config, :format => :xml, :headers => { 'content-type' => 'application/xml' }) self.class.post("/createItem/api/xml?name=#{CGI.escape(job)}", ) end |
#create_job_configuration(repo, branch) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kraken-build/jenkins-api.rb', line 40 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 |
#get_job_configuration(job, options = {}) ⇒ Object
56 57 58 59 60 |
# File 'lib/kraken-build/jenkins-api.rb', line 56 def get_job_configuration(job, = {}) response = self.class.get("/job/#{job}/config.xml", ) response.body end |
#get_jobs(options = {}) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/kraken-build/jenkins-api.rb', line 23 def get_jobs( = {}) response = self.class.get("/api/json/", ) jobs = response["jobs"] jobs.map { |job| job["name"] } end |
#remove_job(job_name, options = {}) ⇒ Object
62 63 64 |
# File 'lib/kraken-build/jenkins-api.rb', line 62 def remove_job(job_name, ={}) self.class.post("/job/#{CGI.escape(job_name)}/doDelete") end |