class DynportTools::Jenkins
Constants
- CONFIGURED_PROJECTS_HASH
Attributes
url[RW]
Public Class Methods
new(url = nil)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 4 def initialize(url = nil) self.url = url end
Public Instance Methods
build_project(name)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 24 def build_project(name) send_to_project(name, "build") end
cache()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 49 def cache @cache ||= {} end
clear_cache()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 45 def clear_cache cache.clear end
configured_projects()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 91 def configured_projects configured_projects_hash.values end
configured_projects_hash()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 87 def configured_projects_hash @configured_projects_hash ||= {} end
configured_projects_hash=(new_hash)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 83 def configured_projects_hash=(new_hash) @configured_projects_hash = new_hash end
create_project(name, xml)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 12 def create_project(name, xml) post_request "createItem?name=#{escape_job_name(name)}", :headers => { "Content-Type" => "application/xml" }, :body => xml end
delete_project(name)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 20 def delete_project(name) send_to_project(name, "doDelete") end
disable_project(name)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 28 def disable_project(name) send_to_project(name, "disable") end
enable_project(name)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 32 def enable_project(name) send_to_project(name, "enable") end
escape_job_name(name)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 53 def escape_job_name(name) URI.escape(name) end
exists_remotely?(project)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 102 def exists_remotely?(project) remote_projects.keys.include?(project.name) end
hydra()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 8 def hydra @hydra ||= Typhoeus::Hydra.new end
not_configured_projects()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 118 def not_configured_projects remote_projects.values.select { |project| !configured_projects_hash.keys.include?(project.name) } end
post_request(path, options = nil)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 40 def post_request(path, options = nil) clear_cache Typhoeus::Request.post(*["#{url}/#{path}", options].compact) end
project_details()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 66 def project_details return cache[:projects_details] if cache[:projects_details] jobs = {} projects_hash.each do |url, job| request = Typhoeus::Request.new("#{url}config.xml") request.on_complete do |response| xml = Nokogiri::XML(response.body).to_s jobs[url] = job.merge(:body => xml, :md5 => Digest::MD5.hexdigest(xml)) end hydra.queue(request) end hydra.run cache[:projects_details] = jobs end
projects_hash()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 57 def projects_hash cache[:projects_hash] ||= Nokogiri::XML(Typhoeus::Request.get("#{url}/api/xml").body).search("job").inject({}) do |hash, node| url = node.at("url").inner_text.strip if node.at("url") name = node.at("name").inner_text.strip if node.at("name") hash[url] = { :url => url, :name => name } hash end end
projects_to_create()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 110 def projects_to_create configured_projects.select { |project| !project.deleted? && !exists_remotely?(project) } end
projects_to_delete()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 106 def projects_to_delete configured_projects.select { |project| project.deleted? && exists_remotely?(project) } end
projects_to_update()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 114 def projects_to_update configured_projects.select { | project| exists_remotely?(project) && !project.deleted? && (project.md5 != remote_projects[project.name].md5) } end
remote_projects()
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 95 def remote_projects project_details.inject({}) do |hash, (url, project_hash)| hash[project_hash[:name]] = RemoteProject.from_details_hash(project_hash) hash end end
send_to_project(name, action)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 36 def send_to_project(name, action) post_request "job/#{escape_job_name(name)}/#{action}" end
update_project(name, xml)
click to toggle source
# File lib/dynport_tools/jenkins.rb, line 16 def update_project(name, xml) post_request "job/#{escape_job_name(name)}/config.xml", :headers => { "Content-Type" => "application/xml" }, :body => xml end