remote_jenkins_job 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ Remote Jenkins Job
2
+ ==================
3
+
4
+ This script allows a job on a local instance of [Jenkins](http://jenkins-ci.org) to invoke a job on a remote instance of Jenkins.
5
+ The local job will only pass when the remote job passes.
6
+
7
+ This script has only been tested with ruby 1.9.2
8
+
9
+ Installation
10
+ ------------
11
+
12
+ On the server that Jenkins is installed on, and as the jenkins user, run:
13
+ `gem install remote_jenkins_job`
14
+
15
+ Usage
16
+ -----
17
+
18
+ Create a new free-style software project.
19
+
20
+ Add a build step, and enter the following command:
21
+ `remote_jenkins_job <remote-job-url> <username> <password>`
22
+
23
+ (username and password are optional - only required if your remote jenkins is password protected using HTTP Basic Authentication)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ #require 'net/http'
5
+ #Net::HTTP.get URI.parse('http://remote.example.com/job/foo/build')
6
+ #puts 'alkesh'
7
+ require 'remote_jenkins_job'
8
+ RemoteJenkinsJob.new ARGV
@@ -0,0 +1,74 @@
1
+ require 'json'
2
+ require 'net/https'
3
+ require 'open-uri'
4
+ require 'uri'
5
+
6
+ class RemoteJenkinsJob
7
+ def initialize params=[]
8
+ if params.empty?
9
+ puts "Usage: remote_jenkins_job [job uri] ([username] [password])"
10
+ else
11
+ @job_uri = params[0]
12
+ if params[1]
13
+ @basic_auth = [params[1], params[2]]
14
+ @options = {:http_basic_authentication => @basic_auth}
15
+ else
16
+ @options = {}
17
+ end
18
+ start
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def start
25
+ puts "Running remote job: #{@job_uri}"
26
+ original_last_build = get_last_build
27
+ puts "Last build was: " + original_last_build['url'].to_s
28
+
29
+ post_build_request
30
+
31
+ last_build = original_last_build
32
+ while last_build == original_last_build do
33
+ last_build = get_last_build
34
+ print '.'
35
+ sleep 1
36
+ end
37
+
38
+ puts ""
39
+ puts "New build started: #{last_build['url']}"
40
+
41
+ while (latest_build = get_new_build(last_build['url']))['building'] do
42
+ print '.'
43
+ sleep 1
44
+ end
45
+
46
+ puts ""
47
+ puts "Build result: " + latest_build['result']
48
+
49
+ exit(1) unless latest_build['result'] == 'SUCCESS'
50
+ end
51
+
52
+ def get_last_build
53
+ json = JSON.parse(open(@job_uri+"/api/json", @options).read)
54
+ json['lastBuild']
55
+ end
56
+
57
+ def get_new_build(url)
58
+ uri = URI.parse(url+'api/json')
59
+ uri.userinfo=''
60
+ JSON.parse(open(uri.to_s, @options).read)
61
+ end
62
+
63
+ def post_build_request
64
+ proxy_uri = URI.parse(ENV['http_proxy']) if ENV['http_proxy']
65
+ proxy_host, proxy_port = proxy_uri.host, proxy_uri.port if ENV['http_proxy']
66
+ url = URI.parse(@job_uri+'/build')
67
+ use_ssl = true if url.scheme == 'https'
68
+ Net::HTTP::Proxy(proxy_host, proxy_port).start(url.host, url.port, :use_ssl => use_ssl) do |http|
69
+ request = Net::HTTP::Post.new(url.request_uri)
70
+ request.basic_auth @basic_auth[0], @basic_auth[1] if @basic_auth
71
+ http.request(request)
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remote_jenkins_job
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Alkesh Vaghmaria
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-22 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Inovkes a job on a remote jenkins server
34
+ email: alkesh.vaghmaria@bt.com
35
+ executables:
36
+ - remote_jenkins_job
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README.md
41
+ files:
42
+ - README.md
43
+ - lib/remote_jenkins_job.rb
44
+ - bin/remote_jenkins_job
45
+ has_rdoc: true
46
+ homepage: https://github.com/alkesh/jenkins-remote-job
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --main
52
+ - README.md
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Inovkes a job on a remote jenkins server
78
+ test_files: []
79
+