diff --git a/lib/jenkins_api_client/build_queue.rb b/lib/jenkins_api_client/build_queue.rb index 09a294e6..95a75368 100644 --- a/lib/jenkins_api_client/build_queue.rb +++ b/lib/jenkins_api_client/build_queue.rb @@ -82,6 +82,23 @@ def get_age(task_name) age end + # Obtains ALL queue items with detail Hash from the API response + # + # @param [String] task_name Name of the task/job + # + # @return [Hash] Queue details of the specified task/job + # + def get_all_with_details(task_name) + @logger.info "Obtaining all queue items with details of task '#{task_name}' from the" + + " build queue" + response_json = @client.api_get_request("/queue/api/json") + details = [] + response_json["items"].each do |item| + details << item if item["task"]["name"] == task_name + end + details + end + # Obtains the detail Hash from the API response # # @param [String] task_name Name of the task/job diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index cee4c2cb..87d61005 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -114,7 +114,7 @@ class Client def initialize(args) args = symbolize_keys(args) args.each do |key, value| - if value && VALID_PARAMS.include?(key.to_s) + if VALID_PARAMS.include?(key.to_s) instance_variable_set("@#{key}", value) end end if args.is_a? Hash @@ -363,7 +363,14 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER - http.ca_file = @ca_file if @ca_file + + if @ca_file + http.ca_file = @ca_file + else + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + else + http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout diff --git a/lib/jenkins_api_client/job.rb b/lib/jenkins_api_client/job.rb index 30d7dc9c..09faa823 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -731,6 +731,27 @@ def get_builds(job_name, options = {}) response_json["builds"] end + # Obtain build details of a single build + # + # @param [String] job_name + # + # @param [Number] build_number + # + # @return [Hash] Build details of the specified build + # + def get_build_details(job_name, build_number = nil, options = {}) + if build_number.nil? + build_number = get_current_build_number(job_name) + end + + @logger.info "Obtaining the build details of '#{job_name}' / build ##{build_number}" + url = "/job/#{path_encode job_name}/#{build_number}/api/json" + + tree = options[:tree] || nil + response_json = @client.api_get_request url, tree_string(tree) + response_json["builds"] + end + # This method maps the color to status of a job # # @param [String] color color given by the API for a job