Permalink
Browse files

work when http_proxy set

  • Loading branch information...
1 parent c75c334 commit a2548ea3a96327874a55a407aae5baab1e259d3e Alkesh Vaghmaria committed Aug 22, 2011
Showing with 27 additions and 17 deletions.
  1. +13 −5 Rakefile
  2. +4 −0 features/step_definitions/remote_job_steps.rb
  3. +0 −5 features/support/env.rb
  4. +8 −5 lib/remote_jenkins_job.rb
  5. +2 −2 remote_jenkins_job.gemspec
View
18 Rakefile
@@ -3,15 +3,23 @@ require "rubygems/package_task"
require "rdoc/task"
require "cucumber/rake/task"
-task :default => [:cucumber, :package] do
- puts "Don't forget to write some tests!"
-end
+task :default => [:cucumber_with_proxy, :cucumber_without_proxy, :package]
Cucumber::Rake::Task.new :cucumber do |t|
- t.fork = false
+ t.fork = true
t.cucumber_opts = %w{features --format progress}
end
+task :cucumber_with_proxy do
+ ENV['http_proxy']='http://proxy.example.com:8080'
+ Rake::Task['cucumber'].execute
+end
+
+task :cucumber_without_proxy do
+ ENV['http_proxy']=nil
+ Rake::Task['cucumber'].execute
+end
+
# This builds the actual gem. For details of what all these options
# mean, and other ones you can add, check the documentation here:
#
@@ -21,7 +29,7 @@ spec = Gem::Specification.new do |s|
# Change these as appropriate
s.name = "remote_jenkins_job"
- s.version = "1.0.0"
+ s.version = "1.0.1"
s.summary = "Inovkes a job on a remote jenkins server"
s.description = "Inovkes a job on a remote jenkins server"
s.author = "Alkesh Vaghmaria"
View
4 features/step_definitions/remote_job_steps.rb
@@ -28,6 +28,10 @@
to_return(:body => %({"building":false, "result":"SUCCESS"}))
end
+When /^a remote job that needs to be accessed via a proxy is set to pass$/ do
+ ENV['http_proxy']='http://proxy.example.com:8080'
+end
+
Then /^the remote build should be invoked$/ do
@remote_build_request.should have_been_requested
end
View
5 features/support/env.rb
@@ -2,8 +2,3 @@
require 'rspec/expectations'
require 'webmock/cucumber'
require File.dirname(__FILE__) + '/../../lib/remote_jenkins_job'
-#World(Rspec::Matchers)
-
-#Before do
- #WebMock.reset!
-#end
View
13 lib/remote_jenkins_job.rb
@@ -61,11 +61,14 @@ def get_new_build(url)
end
def post_build_request
+ proxy_uri = URI.parse(ENV['http_proxy']) if ENV['http_proxy']
+ proxy_host, proxy_port = proxy_uri.host, proxy_uri.port if ENV['http_proxy']
url = URI.parse(@job_uri+'/build')
- http = Net::HTTP.new(url.host, url.port)
- http.use_ssl = true if url.scheme == 'https'
- request = Net::HTTP::Post.new(url.request_uri)
- request.basic_auth @basic_auth[0], @basic_auth[1] if @basic_auth
- http.request(request)
+ use_ssl = true if url.scheme == 'https'
+ Net::HTTP::Proxy(proxy_host, proxy_port).start(url.host, url.port, :use_ssl => use_ssl) do |http|
+ request = Net::HTTP::Post.new(url.request_uri)
+ request.basic_auth @basic_auth[0], @basic_auth[1] if @basic_auth
+ http.request(request)
+ end
end
end
View
4 remote_jenkins_job.gemspec
@@ -2,11 +2,11 @@
Gem::Specification.new do |s|
s.name = %q{remote_jenkins_job}
- s.version = "1.0.0"
+ s.version = "1.0.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Alkesh Vaghmaria"]
- s.date = %q{2011-08-19}
+ s.date = %q{2011-08-22}
s.default_executable = %q{remote_jenkins_job}
s.description = %q{Inovkes a job on a remote jenkins server}
s.email = %q{alkesh.vaghmaria@bt.com}

0 comments on commit a2548ea

Please sign in to comment.