From 58cdbf6b339831c5f8e1ed0f63ed5b108712a35e Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Sat, 5 Jun 2021 21:40:41 -0400 Subject: [PATCH 01/14] New endpoints --- lib/jenkins_api_client/build_queue.rb | 17 +++++++++++++++++ lib/jenkins_api_client/job.rb | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) 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/job.rb b/lib/jenkins_api_client/job.rb index 30d7dc9c..7c095893 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -731,6 +731,23 @@ def get_builds(job_name, options = {}) response_json["builds"] end + # Obtain build details of a single build + # + # @param [String] job_name + # + 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 From a3e06f7ab403632f54837d6eff1988b2d3a71706 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 08:05:31 -0400 Subject: [PATCH 02/14] Bug fix --- lib/jenkins_api_client/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index cee4c2cb..9fd64218 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -130,7 +130,7 @@ def initialize(args) server_uri = URI.parse(@server_url) @server_ip = server_uri.host @server_port = server_uri.port - @ssl = server_uri.scheme == "https" + @ssl = server_uri.scheme == "https" && @ssl @jenkins_path = server_uri.path # read username and password from the URL From 8baa591690c4dccc513320012219a60cf6c6d4e3 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 08:11:11 -0400 Subject: [PATCH 03/14] debug --- lib/jenkins_api_client/client.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 9fd64218..1532d788 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -368,6 +368,8 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout + puts "[Jenkins API] SSL = #{@ssl}" + puts "[Jenkins API] request = #{request}" response = http.request(request) case response when Net::HTTPRedirection then From 47c57c5d747e2d9a48725115ee0c376a8d7bac41 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 08:14:26 -0400 Subject: [PATCH 04/14] Bug fix --- lib/jenkins_api_client/client.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 1532d788..8609e3ab 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -368,8 +368,8 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout - puts "[Jenkins API] SSL = #{@ssl}" - puts "[Jenkins API] request = #{request}" + @logger.info "[Jenkins API] SSL = #{@ssl}" + @logger.info "[Jenkins API] request = #{request}" response = http.request(request) case response when Net::HTTPRedirection then From 59c00e031707d3ad5382827aa0a70e6013b57a80 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 11:46:45 -0400 Subject: [PATCH 05/14] Skip certificate check --- lib/jenkins_api_client/client.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 8609e3ab..b20cc45c 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -369,6 +369,7 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.read_timeout = @http_read_timeout @logger.info "[Jenkins API] SSL = #{@ssl}" + http.verify_mode = OpenSSL::SSL::VERIFY_NONE @logger.info "[Jenkins API] request = #{request}" response = http.request(request) case response From 4098068eafec29c6226cd3f6a55dcb1e061160bf Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:13:31 -0400 Subject: [PATCH 06/14] Bug fix --- lib/jenkins_api_client/client.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index b20cc45c..97745379 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -130,7 +130,7 @@ def initialize(args) server_uri = URI.parse(@server_url) @server_ip = server_uri.host @server_port = server_uri.port - @ssl = server_uri.scheme == "https" && @ssl + @ssl = server_uri.scheme == "https" @jenkins_path = server_uri.path # read username and password from the URL @@ -364,13 +364,12 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.ca_file = @ca_file if @ca_file + else + http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout - @logger.info "[Jenkins API] SSL = #{@ssl}" - http.verify_mode = OpenSSL::SSL::VERIFY_NONE - @logger.info "[Jenkins API] request = #{request}" response = http.request(request) case response when Net::HTTPRedirection then @@ -509,7 +508,7 @@ def post_json(url_prefix, json) end def post_data(url_prefix, data, content_type) - retries = @crumb_max_retries + retries = @crumb_max_retrie begin refresh_crumbs From 085139c362fb0dd56a242bff9ea9babf7874585e Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:17:35 -0400 Subject: [PATCH 07/14] Logging --- lib/jenkins_api_client/client.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 97745379..e9fee6a3 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -370,6 +370,9 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout + @logger.info("[Jenkins API] http.use_ssl?: #{http.use_ssl?}") + @logger.info("[Jenkins API] http.verify_mode: #{http.verify_mode}") + response = http.request(request) case response when Net::HTTPRedirection then From 925f7b9b36b47b809e1bb5414478a4c0ca3c76ed Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:37:08 -0400 Subject: [PATCH 08/14] Bug fix --- lib/jenkins_api_client/client.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index e9fee6a3..68718c3e 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 @@ -130,7 +130,7 @@ def initialize(args) server_uri = URI.parse(@server_url) @server_ip = server_uri.host @server_port = server_uri.port - @ssl = server_uri.scheme == "https" + @ssl = server_uri.scheme == "https" && @ssl @jenkins_path = server_uri.path # read username and password from the URL @@ -370,9 +370,6 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout - @logger.info("[Jenkins API] http.use_ssl?: #{http.use_ssl?}") - @logger.info("[Jenkins API] http.verify_mode: #{http.verify_mode}") - response = http.request(request) case response when Net::HTTPRedirection then From 533a9d0c02dfc97cbe363d31ff7d6213382562b8 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:44:08 -0400 Subject: [PATCH 09/14] No verify when no certificate is passed --- lib/jenkins_api_client/client.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 68718c3e..d5ce1abb 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -363,7 +363,12 @@ 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 From c778acf43e2370f6108be870b480576c16a5e72c Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:49:11 -0400 Subject: [PATCH 10/14] Bug fix --- lib/jenkins_api_client/client.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index d5ce1abb..f8e2fae6 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -375,6 +375,9 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout + @logger.info("[Jenkins API] http.use_ssl? = #{http.use_ssl?}") + @logger.info("[Jenkins API] http.verify_mode = #{http.verify_mode}") + response = http.request(request) case response when Net::HTTPRedirection then From 7eb63cac17b18db37d1894229c47792ec7fb6eb6 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:51:03 -0400 Subject: [PATCH 11/14] Bug fix --- lib/jenkins_api_client/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index f8e2fae6..a75314d1 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -130,7 +130,7 @@ def initialize(args) server_uri = URI.parse(@server_url) @server_ip = server_uri.host @server_port = server_uri.port - @ssl = server_uri.scheme == "https" && @ssl + @ssl = server_uri.scheme == "https" @jenkins_path = server_uri.path # read username and password from the URL From b6e13ee98bcb14c1aa9c2359ad9b9137e6ea2279 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 12:57:01 -0400 Subject: [PATCH 12/14] Removed logging --- lib/jenkins_api_client/client.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index a75314d1..4ae812ee 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -375,9 +375,6 @@ def make_http_request(request, follow_redirect = @follow_redirects) http.open_timeout = @http_open_timeout http.read_timeout = @http_read_timeout - @logger.info("[Jenkins API] http.use_ssl? = #{http.use_ssl?}") - @logger.info("[Jenkins API] http.verify_mode = #{http.verify_mode}") - response = http.request(request) case response when Net::HTTPRedirection then From 244aa69ead6c302e8f63be61fe2f9cb1cd6e21d8 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 15:01:51 -0400 Subject: [PATCH 13/14] Must've removed by mistake --- lib/jenkins_api_client/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 4ae812ee..87d61005 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -513,7 +513,7 @@ def post_json(url_prefix, json) end def post_data(url_prefix, data, content_type) - retries = @crumb_max_retrie + retries = @crumb_max_retries begin refresh_crumbs From 20c403c2e1332066063112ecfa0fb0dc5025a541 Mon Sep 17 00:00:00 2001 From: Prasad Anne Date: Mon, 7 Jun 2021 20:47:17 -0400 Subject: [PATCH 14/14] Documentation --- lib/jenkins_api_client/job.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/jenkins_api_client/job.rb b/lib/jenkins_api_client/job.rb index 7c095893..09faa823 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -735,6 +735,10 @@ def get_builds(job_name, options = {}) # # @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)