Class: Test::Drive::JenkinsClient
- Inherits:
-
Object
- Object
- Test::Drive::JenkinsClient
- Defined in:
- lib/test/drive/jenkins_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #get_build_number(target_job, tracking_id, timeout_in_seconds, sleep_interval = 10) ⇒ Object
-
#initialize(jenkins_url, user, api_key) ⇒ JenkinsClient
constructor
A new instance of JenkinsClient.
- #print_output(build_number, target_job) ⇒ Object
- #upload_file_to_job(target_job, tracking_id, path_to_file) ⇒ Object
- #wait_for_job_status(target_job, build_number) ⇒ Object
Constructor Details
#initialize(jenkins_url, user, api_key) ⇒ JenkinsClient
Returns a new instance of JenkinsClient.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/test/drive/jenkins_client.rb', line 8 def initialize jenkins_url, user, api_key @jenkins_url = jenkins_url @user = user @api_key = api_key @client = JenkinsApi::Client.new :server_url => jenkins_url, :username => user, :password => api_key, :log_level => 1 end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6 7 8 |
# File 'lib/test/drive/jenkins_client.rb', line 6 def client @client end |
Instance Method Details
#get_build_number(target_job, tracking_id, timeout_in_seconds, sleep_interval = 10) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/test/drive/jenkins_client.rb', line 19 def get_build_number(target_job, tracking_id, timeout_in_seconds, sleep_interval=10) (timeout_in_seconds/10).times do sleep sleep_interval build_details = @client.job.get_build_details(target_job, 0) if build_details['actions'][0]['parameters'].include?(tracking_id) return build_details['number'] end end raise 'Build number not found within the time specified!' end |
#print_output(build_number, target_job) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/test/drive/jenkins_client.rb', line 30 def print_output(build_number, target_job) offset = 0 loop do job_output = @client.job.get_console_output(target_job, build_number, offset) print job_output['output'] break unless job_output['more'] offset = job_output['size'] end end |
#upload_file_to_job(target_job, tracking_id, path_to_file) ⇒ Object
50 51 52 53 |
# File 'lib/test/drive/jenkins_client.rb', line 50 def upload_file_to_job(target_job, tracking_id, path_to_file) res = `curl -i #{@jenkins_url}/job/#{target_job}/build -F file0=@#{path_to_file} -F json='{"parameter": [{"name":"#{path_to_file}", "file":"file0"}, {"name":"TRACKING_ID", "value":"#{tracking_id}"}]}' --user '#{@user}':'#{@api_key}'` raise "Failed to send patch to Jenkins: \n#{res}" unless $? == 0 end |
#wait_for_job_status(target_job, build_number) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/test/drive/jenkins_client.rb', line 42 def wait_for_job_status(target_job, build_number) loop do details = @client.job.get_build_details(target_job, build_number) return details['result'] if details['result'] sleep 5 end end |