From 507b2b05b23a6bd58e1b3d1cd6f54f435a1e8659 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 12 Feb 2020 13:51:13 +0100 Subject: [PATCH] Solves bug: Jenkins response msg is not always between html p tabs. Some other times it is between html h2 tags. --- lib/jenkins_api_client/client.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index cee4c2cb..668fc19c 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -815,8 +815,7 @@ def handle_exception(response, to_send = "code", send_json = false) return response end when 400 - matched = response.body.match(/

(.*)<\/p>/) - api_message = matched[1] unless matched.nil? + api_message = getApiMsgFromError404 response @logger.debug "API message: #{api_message}" case api_message when /A job already exists with the name/ @@ -851,5 +850,24 @@ def handle_exception(response, to_send = "code", send_json = false) end end + def getApiMsgFromError404(response) + + matched = response.body.match(/

(.*)<\/p>/) + # unless matched.nil? + if (matched != nil) + result = matched[1] + else + + matched = response.body.match(/

(.*)<\/h2>/) + if (matched != nil) + result = matched[1] + else + result = nil + end + end + + return result + end + end end