diff --git a/.travis.yml b/.travis.yml index 3e0a6231..7af4b5f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ rvm: - 2.5.8 - 2.6.6 - 2.7.1 + - 3.0.0 script: - bundle exec rake unit_tests diff --git a/jenkins_api_client.gemspec b/jenkins_api_client.gemspec index 37061a61..38ba6c14 100644 --- a/jenkins_api_client.gemspec +++ b/jenkins_api_client.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |s| s.files = `git ls-files -z`.split("\x0").select { |f| f.match(%r{lib/|bin/|java_deps/|gemspec}) } s.require_paths = ['lib'] s.homepage = 'https://github.com/arangamani/jenkins_api_client' - s.required_ruby_version = ::Gem::Requirement.new('~> 2.1') - s.rubygems_version = "2.4.5.1" + s.required_ruby_version = ::Gem::Requirement.new('>= 2.0.0') + s.rubygems_version = "3.2.15" s.summary = "Jenkins JSON API Client" s.licenses = ["MIT"] diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index cee4c2cb..d2327851 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -385,6 +385,7 @@ def make_http_request(request, follow_redirect = @follow_redirects) # Pick out some useful header info before we return @jenkins_version = response['X-Jenkins'] @hudson_version = response['X-Hudson'] + set_cookie(response) return response end @@ -694,6 +695,16 @@ def exec_cli(command, args = []) private + # Handles Set-Cookie header for jenkins session + # + def set_cookie(response) + cookie = response['Set-Cookie'] + return unless cookie + + @logger.debug "Setting cookie: @cookies: #{@cookies}, cookie: #{cookie}" + @cookies = @cookies ? "#{@cookies};#{cookie}" : cookie + end + # Obtains the crumb from Jenkins' crumb issuer # # @return [Hash] the crumb response from Jenkins' crumb diff --git a/lib/jenkins_api_client/job.rb b/lib/jenkins_api_client/job.rb index 30d7dc9c..85ede031 100644 --- a/lib/jenkins_api_client/job.rb +++ b/lib/jenkins_api_client/job.rb @@ -1687,7 +1687,7 @@ def artifact_exists?(job_name, build_number = 0) def find_artifacts(job_name, build_number = nil) response_json = get_build_details(job_name, build_number) artifact_path(build_details: response_json).map do |p| - URI.escape("#{response_json['url']}artifact/#{p['relativePath']}") + CGI.escape("#{response_json['url']}artifact/#{p['relativePath']}") end end diff --git a/spec/unit_tests/job_spec.rb b/spec/unit_tests/job_spec.rb index 3863cd5e..4ca7f1b2 100644 --- a/spec/unit_tests/job_spec.rb +++ b/spec/unit_tests/job_spec.rb @@ -710,13 +710,13 @@ describe "#find_artifact" do it "accepts job name and build number and return artifact path" do - expected_path = URI.escape("https://example.com/DEFAULT-VIEW/view/VIEW-NAME/job/test_job/2/artifact/somepath/output.json") + expected_path = CGI.escape("https://example.com/DEFAULT-VIEW/view/VIEW-NAME/job/test_job/2/artifact/somepath/output.json") @client.should_receive(:api_get_request).and_return(@sample_json_build_response) expect(@job.find_artifact('test_job', 1)).to eql(expected_path) end it "accepts job name and uses latest build number if build number not provided and return artifact path" do - expected_path = URI.escape("https://example.com/DEFAULT-VIEW/view/VIEW-NAME/job/test_job/2/artifact/somepath/output.json") + expected_path = CGI.escape("https://example.com/DEFAULT-VIEW/view/VIEW-NAME/job/test_job/2/artifact/somepath/output.json") @client.should_receive(:api_get_request).and_return(@sample_json_job_response, @sample_json_build_response) expect(@job.find_artifact('test_job')).to eql(expected_path) end