Module: Capistrano::JenkinsCap
- Defined in:
- lib/jenkins_cap.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build_has_revision?(build_number) ⇒ Boolean
- #build_passed?(build_number) ⇒ Boolean
- #get_builds ⇒ Object
- #get_revision_from_build(build_number) ⇒ Object
- #json_request(url) ⇒ Object
- #revision_passed? ⇒ Boolean
Class Method Details
.load_into(configuration) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/jenkins_cap.rb', line 61 def self.load_into(configuration) configuration.load do namespace :jenkins_cap do desc "Check if this deployment as a good Jenkins build" task "build_check" do abort "\n\n\nThis revision #{revision} has not been built by Jenkins successfully!\n\n\n".red unless jenkins.revision_passed? puts "\n Revision #{revision} has passed Jenkins tests.\n".green end # end of task end # end of namespace end # end of configuration.load end |
Instance Method Details
#build_has_revision?(build_number) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/jenkins_cap.rb', line 36 def build_has_revision?(build_number) build_revision = get_revision_from_build(build_number) #puts build_revision build_revision.to_i == revision.to_i end |
#build_passed?(build_number) ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/jenkins_cap.rb', line 42 def build_passed?(build_number) json_results = json_request("#{jenkins_host}/job/#{jenkins_job_name}/#{build_number}/api/json") json_results['result'] == "SUCCESS" rescue NoMethodError => e puts "WARNING: #{e}".yellow end |
#get_builds ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/jenkins_cap.rb', line 17 def get_builds() json_results = json_request("#{jenkins_host}/job/#{jenkins_job_name}/api/json") builds = [] json_results['builds'].each{|b| builds << b['number']} builds rescue NoMethodError => e puts "WARNING: #{e}".yellow end |
#get_revision_from_build(build_number) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/jenkins_cap.rb', line 26 def get_revision_from_build(build_number) json_results = json_request("#{jenkins_host}/job/#{jenkins_job_name}/#{build_number}/api/json") return nil if json_results['changeSet']['revisions'].nil? revisions = [] json_results['changeSet']['revisions'].each{|r| revisions << r['revision']} revisions.sort.last rescue NoMethodError => e puts "WARNING: #{e}".yellow end |
#json_request(url) ⇒ Object
12 13 14 15 |
# File 'lib/jenkins_cap.rb', line 12 def json_request(url) response = `wget -q -O - #{url}` JSON.load(response) end |
#revision_passed? ⇒ Boolean
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jenkins_cap.rb', line 49 def revision_passed?() builds_list = get_builds() return false if builds_list.nil? builds_list.each do |build_number| if build_has_revision?(build_number) # check if build has the revision we care about return build_passed?(build_number) end end false end |