Class: Houston::Adapters::CIServer::JenkinsAdapter::Job
- Inherits:
-
Object
- Object
- Houston::Adapters::CIServer::JenkinsAdapter::Job
- Defined in:
- app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #build!(commit) ⇒ Object
- #build_path(commit) ⇒ Object
- #fetch_results!(build_url) ⇒ Object
-
#initialize(project) ⇒ Job
constructor
A new instance of Job.
- #job_path ⇒ Object
- #job_url ⇒ Object
- #last_build_progress_url ⇒ Object
- #last_build_url ⇒ Object
Constructor Details
#initialize(project) ⇒ Job
Returns a new instance of Job.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 7 def initialize(project) @project = project config = Houston.config.ci_server_configuration(:jenkins) protocol = "http" protocol = "https" if config[:port] == 443 jenkins_url = "#{protocol}://#{config[:host]}" jenkins_url << ":#{config[:port]}" unless [80, 443].member?(config[:port]) @connection = Faraday.new(url: jenkins_url) @connection.basic_auth config[:username], config[:password] if config[:username] && config[:password] end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
21 22 23 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 21 def connection @connection end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
21 22 23 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 21 def project @project end |
Instance Method Details
#build!(commit) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 47 def build!(commit) url = build_path(commit) Houston.try({max_tries: 5}, Faraday::Error::ConnectionFailed) do Rails.logger.info "[jenkins] POST #{url}" response = connection.post(url) build_error!(url) unless [200, 201, 302].member?(response.status) response end end |
#build_path(commit) ⇒ Object
31 32 33 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 31 def build_path(commit) "#{job_path}/buildWithParameters?COMMIT_SHA=#{commit}" end |
#fetch_results!(build_url) ⇒ Object
57 58 59 60 61 62 63 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 57 def fetch_results!(build_url) build_url = build_url.chomp("/") results = {} results.merge! fetch_overall_report!(build_url) results.merge! fetch_test_report!(build_url) results.merge! fetch_coverage_report!(build_url) end |
#job_path ⇒ Object
27 28 29 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 27 def job_path "/job/#{project.slug}" end |
#job_url ⇒ Object
23 24 25 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 23 def job_url "#{@connection.url_prefix}#{job_path}" end |
#last_build_progress_url ⇒ Object
42 43 44 45 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 42 def last_build_progress_url url = last_build_url url + "/console" if url end |
#last_build_url ⇒ Object
35 36 37 38 39 40 |
# File 'app/adapters/houston/adapters/ci_server/jenkins_adapter/job.rb', line 35 def last_build_url url = "#{job_path}/api/json?tree=lastBuild[url]" response = connection.get(url) last_build_url_error!(url) unless 200 == response.status MultiJson.load(response.body).fetch("lastBuild").fetch("url") end |