jenkins-status-tool 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ ## The Jenkins Status Tool
2
+ Small tool to get the build status from Jenkins.
3
+ Useful for embedding Jenkins CI status images on your Github project.
4
+
5
+
6
+ ## API
7
+ <table border=1>
8
+ <thead align=left>
9
+ <th>Method</th>
10
+ <th>Action</th>
11
+ <th>Info</th>
12
+ <th>Examples</th>
13
+ </thead>
14
+ <tbody>
15
+ <tr>
16
+ <td align=center><b>GET</b></td>
17
+ <td>/project/:project_id/status.json</td>
18
+ <td>Get project status json string</td>
19
+ <td>
20
+ {"status":"pass"}<br/>
21
+ {"status":"fail"}<br/>
22
+ {"status":"unknown"}
23
+ </td>
24
+
25
+ </tr>
26
+
27
+ <tr>
28
+ <td align=center><b>GET</b></td>
29
+ <td>/project/:project_id/status.png</td>
30
+ <td>Get project status image</td>
31
+ <td>
32
+ <img src="https://github.com/kontera-technologies/jenkins-status-tool/raw/master/public/images/pass.png"><br/>
33
+ <img src="https://github.com/kontera-technologies/jenkins-status-tool/raw/master/public/images/fail.png"><br/>
34
+ <img src="https://github.com/kontera-technologies/jenkins-status-tool/raw/master/public/images/unknown.png">
35
+ </td>
36
+ </tr>
37
+
38
+ <tr>
39
+ <td align=center><b>GET</b></td>
40
+ <td>/project/:project_id/rcov.png</td>
41
+ <td>Get project rcov graph image</td>
42
+ <td>
43
+ <img src="https://github.com/kontera-technologies/jenkins-status-tool/raw/master/readme-files/rcov.png"><br/>
44
+ </td>
45
+
46
+ </tr>
47
+
48
+
49
+ </tbody>
50
+ </table>
51
+
52
+
53
+ ## Installation
54
+ currently available only via source
55
+
56
+ ```bash
57
+ [root@far-far-away] git clone git@github.com:kontera-technologies/jenkins-status-tool.git
58
+ [root@far-far-away] bundle install
59
+ [root@far-far-away] bundle exec rake install
60
+ ```
61
+
62
+ ## Usage
63
+ after installing the gem, the `jenkins-status-tool` command should be available
64
+
65
+ ```bash
66
+ [root@far-far-away] jenkins-status-tool --help
67
+
68
+ The Jenkins Status Tool
69
+ Usage: jenkins-status-tool [options]
70
+
71
+ Options:
72
+ -j, --jenkins URL Jenkins url, e.g http://jenkins:8080, default is localhost
73
+ -p, --port URL listening port, default is 7676
74
+ -d, --daemonize run in background
75
+ -P, --pid-file FILE pid file, default /var/run/jenkins-status-tool.pid
76
+ -s, --https use this if running behind https forwarder (e.g stunnel)
77
+
78
+ More Info:
79
+ https://github.com/kontera-technologies/jenkins-status-tool
80
+
81
+ ```
82
+
83
+ ## Example
84
+ lets say that our Jenkins server is running on ```jenkins-server:1234```
85
+
86
+ ```
87
+ [root@far-far-away] jenkins-status-tool --jenkins jenkins-server:1234 --port 5555 --daemonize
88
+ [root@far-far-away] curl http://localhost:5555/project/my-project/status.json
89
+ {"status":"pass"}
90
+ [root@far-far-away] wget http://localhost:5555/project/my-project/status.png
91
+ [...SHOULD DOWNLOAD ONE OF THE IMAGES ABOVE...]
92
+ ```
93
+
94
+ ## Embed it
95
+ you can easily embed the current status of your builds in any html type document.
96
+
97
+ TextLite
98
+
99
+ ```bash
100
+ "!https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png!":http://jenkins.example.com/jobs/PROJET-NAME
101
+ ```
102
+
103
+ RDoc
104
+
105
+ ```bash
106
+ {<img src="https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png" />}[http://jenkins.example.com/jobs/PROJET-NAME]
107
+ ```
108
+
109
+ MarkDown
110
+
111
+ ```bash
112
+ [![Build Status](https://jenkins-status-tool-url/projects/PROJECT-NAME/status.png)](http://jenkins.example.com/jobs/PROJET-NAME)
113
+ ```
114
+
115
+ >
116
+ > **The tunnel...**
117
+ > We used STunnel to route jenkins-status-tool-url:443 <=> jenkins-status-tool-url:5555
118
+ > This allow us to fetch the status images using https.
119
+
120
+ ## Credits
121
+ * Status images by [travis-ci](https://github.com/travis-ci/travis-ci)
@@ -0,0 +1,5 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+
3
+ require 'jenkins-status-tool'
4
+
5
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), '..','lib')
3
+
4
+ # loading app
5
+ require 'jenkins-status-tool'
6
+
7
+ # starting sinatra app
8
+ JenkinsStatusTool::Runner.new(ARGV).run!
9
+
10
+ # w/o any stupid exit handlers
11
+ Process.exit!
@@ -0,0 +1,16 @@
1
+ module JenkinsStatusTool
2
+ ROOT = File.expand_path File.dirname __FILE__
3
+
4
+ autoload :Version, "#{ROOT}/jenkins-status-tool/version"
5
+ autoload :WebApp, "#{ROOT}/jenkins-status-tool/webapp"
6
+ autoload :Runner, "#{ROOT}/jenkins-status-tool/runner"
7
+ autoload :Config, "#{ROOT}/jenkins-status-tool/config"
8
+ autoload :Utils, "#{ROOT}/jenkins-status-tool/utils"
9
+ autoload :JenkinsBroker, "#{ROOT}/jenkins-status-tool/jenkins-broker"
10
+ autoload :JenkinsProject, "#{ROOT}/jenkins-status-tool/jenkins-project"
11
+
12
+ def self.version
13
+ Version::VERSION
14
+ end
15
+
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'ostruct'
2
+ require 'singleton'
3
+
4
+ module JenkinsStatusTool
5
+ class Config < OpenStruct
6
+ include Singleton
7
+
8
+ def initialize
9
+ super
10
+ self.port = 7676
11
+ self.jenkins = "localhost:8080"
12
+ self.pid = '/var/run/jenkins-status-tool.pid'
13
+ self.root = File.expand_path File.join(JenkinsStatusTool::ROOT, "..")
14
+ self.https = false
15
+ end
16
+
17
+ def https?
18
+ self.https
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'open-uri'
3
+ require 'singleton'
4
+ require 'json'
5
+
6
+ module JenkinsStatusTool
7
+ class JenkinsBroker
8
+ include Singleton
9
+
10
+ def project_info project
11
+ json["jobs"].select {|o| o["name"] == project}.first rescue Hash.new
12
+ end
13
+
14
+ def project_rcov_graph project
15
+ open("http://#{Config.instance.jenkins}/job/#{project}/rcov/graph").read rescue nil
16
+ end
17
+
18
+ private
19
+ def json
20
+ JSON.parse open("http://#{Config.instance.jenkins}/api/json").read
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'ostruct'
2
+
3
+ module JenkinsStatusTool
4
+ class JenkinsProject < OpenStruct
5
+
6
+ def initialize hash
7
+ super
8
+ self.project = hash.fetch :project
9
+ self.jenkins = JenkinsBroker::instance
10
+ end
11
+
12
+ def status
13
+ case color
14
+ when :red then :fail
15
+ when :blue then :pass
16
+ when :gray then :inactive
17
+ else :unknown
18
+ end
19
+ end
20
+
21
+ def color
22
+ data["color"].to_sym
23
+ end
24
+
25
+ def rcov_image
26
+ jenkins.project_rcov_graph project
27
+ end
28
+
29
+ private
30
+
31
+ def data
32
+ jenkins.project_info project
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,67 @@
1
+ require 'optparse'
2
+
3
+ module JenkinsStatusTool
4
+ class Runner
5
+
6
+ def initialize(argv)
7
+ parser.parse! argv
8
+ end
9
+
10
+ def run!
11
+ config.daemonize ? daemonize! : WebApp.run!
12
+ end
13
+
14
+ private
15
+ def daemonize!
16
+ fork do
17
+ Process.setsid
18
+ exit if fork
19
+ Dir.chdir('/tmp')
20
+ STDOUT.reopen('/dev/null','a')
21
+ STDIN.reopen('/dev/null')
22
+ STDERR.reopen('/dev/null','a')
23
+ File.open(options.pid, 'w') { |f| f.write Process.pid } rescue nil
24
+ WebApp.run!
25
+ end
26
+ end
27
+
28
+ def parser
29
+ OptionParser.new do |opts|
30
+ opts.banner = "The Jenkins Status Tool"
31
+ opts.define_head "Usage: jenkins-status-tool [options]"
32
+ opts.separator ""
33
+ opts.separator "Options:"
34
+
35
+ opts.on('-j', '--jenkins URL', 'Jenkins url, e.g http://jenkins:8080, default is localhost') do |url|
36
+ config.jenkins = url
37
+ end
38
+
39
+ opts.on('-p', '--port URL', 'listening port, default is 7676') do |port|
40
+ config.port = port
41
+ end
42
+
43
+ opts.on("-d", "--daemonize","run in background") do
44
+ config.daemonize = true
45
+ end
46
+
47
+ opts.on("-P", "--pid-file FILE","pid file, default /var/run/jenkins-status-tool.pid") do |file|
48
+ config.pid = file
49
+ end
50
+
51
+ opts.on('-s', '--https', 'add this switch if you are running behind https forwarder (e.g stunnel)') do
52
+ config.https = true
53
+ end
54
+
55
+ opts.separator ""
56
+ opts.separator "More Info:"
57
+ opts.separator "https://github.com/kontera-technologies/jenkins-status-tool"
58
+ opts.separator ""
59
+ end
60
+ end
61
+
62
+ def config
63
+ Config.instance
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ require 'singleton'
2
+
3
+ module JenkinsStatusTool
4
+ module Utils
5
+
6
+ class Singleton
7
+ include Object::Singleton
8
+
9
+ def self.method_missing(m,*a,&b)
10
+ instance.send(m,*a,&b)
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+
@@ -0,0 +1,5 @@
1
+ module JenkinsStatusTool
2
+ class Version
3
+ VERSION = "0.0.4"
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'sinatra/base'
2
+
3
+ module JenkinsStatusTool
4
+ class WebApp < Sinatra::Base
5
+
6
+ set :root, Config::instance.root
7
+ set :port, Config::instance.port
8
+
9
+ get "/" do
10
+ erb :index
11
+ end
12
+
13
+ get "/project/:project/status.?:format?" do
14
+ case format
15
+ when :png then
16
+ redirect "/images/#{project.status}.png"
17
+ when :json then
18
+ {:status => project.status }.to_json
19
+ end
20
+ end
21
+
22
+ get "/project/:project/rcov.?:format?" do
23
+ case format
24
+ when :png then
25
+ content_type 'image/jpeg'
26
+ project.rcov_image or redirect "/images/rcov-no-data.png"
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def redirect path
33
+ if config.https? and relative? path
34
+ super ["https://",request.host,path].join
35
+ else
36
+ super path
37
+ end
38
+ end
39
+
40
+ def relative? path
41
+ path !~ /http(s*)?:\/\//i
42
+ end
43
+
44
+ def format
45
+ symbolize_params.fetch(:format).to_sym
46
+ end
47
+
48
+ def symbolize_params
49
+ @_params ||= Hash[params.map {|a| [a[0].to_sym,a[1]]}]
50
+ end
51
+
52
+ def project
53
+ @project ||= JenkinsProject.new symbolize_params
54
+ end
55
+
56
+ def config
57
+ self.class.config
58
+ end
59
+
60
+ end
61
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,44 @@
1
+ require 'rubygems/package_task'
2
+
3
+ JenkinsStatusTool::GemSpec = Gem::Specification.new do |s|
4
+ s.name = "jenkins-status-tool"
5
+ s.version = JenkinsStatusTool.version
6
+ s.platform = Gem::Platform::RUBY
7
+ s.summary = "JenkinsStatusTool"
8
+ s.description = "JenkinsStatusTool - get jenkins status"
9
+ s.author = "Eran Barak Levi"
10
+ s.email = 'eran@kontera.com'
11
+ s.homepage = 'http://www.kontera.com'
12
+ s.executables = %w(jenkins-status-tool)
13
+ s.required_ruby_version = '>= 1.8.7'
14
+ s.rubyforge_project = "jenkins-status-tool"
15
+ s.files = %w(README.markdown Rakefile) + Dir.glob("{bin,lib,test,tasks,public,views}/**/*")
16
+ s.require_path = "lib"
17
+ s.bindir = "bin"
18
+
19
+ s.add_dependency 'sinatra'
20
+ s.add_dependency 'json'
21
+ end
22
+
23
+ task :gem => [:clobber_package]
24
+ Gem::PackageTask.new(JenkinsStatusTool::GemSpec) do |p|
25
+ p.gem_spec = JenkinsStatusTool::GemSpec
26
+ end
27
+
28
+ task :install => [:gem] do
29
+ sh "gem install pkg/jenkins-status-tool"
30
+ Rake::Task['clobber_package'].execute
31
+ end
32
+
33
+ namespace :gem do
34
+ desc "Upload jenkins-status-tool to Kontera's repo"
35
+ task :upload => [:build] do
36
+ sh "gem inabox --host http://gems.kontera.com pkg/jenkins-status-tool-#{JenkinsStatusTool.version}.gem"
37
+ end
38
+
39
+ desc "Update GraphiteAPI gem version and build gem"
40
+ task :build => [:test] do
41
+ sh "rake gem"
42
+ end
43
+
44
+ end
@@ -0,0 +1,5 @@
1
+ task :test do
2
+ #
3
+ end
4
+
5
+ task :default => [:test]
@@ -0,0 +1,46 @@
1
+ <h2> Jenkins Status Tool API</h2></br>
2
+
3
+ <table border=1>
4
+ <thead align=left>
5
+ <th>Method</th>
6
+ <th>Action</th>
7
+ <th>Info</th>
8
+ <th>Examples</th>
9
+ </thead>
10
+ <tbody>
11
+ <tr>
12
+ <td align=center><b>GET</b></td>
13
+ <td>/project/:project_id/status.json</td>
14
+ <td>Get project status json string</td>
15
+ <td>
16
+ {"status":"pass"}<br/>
17
+ {"status":"fail"}<br/>
18
+ {"status":"unknown"}
19
+ </td>
20
+
21
+ </tr>
22
+
23
+ <tr>
24
+ <td align=center><b>GET</b></td>
25
+ <td>/project/:project_id/status.png</td>
26
+ <td>Get project status image</td>
27
+ <td>
28
+ <img src="/images/pass.png"><br/>
29
+ <img src="/images/fail.png"><br/>
30
+ <img src="/images/unknown.png">
31
+ </td>
32
+ </tr>
33
+
34
+ <tr>
35
+ <td align=center><b>GET</b></td>
36
+ <td>/project/:project_id/rcov.png</td>
37
+ <td>Get project rcov graph image</td>
38
+ <td>
39
+ <img src="/images/rcov-example.png"><br/>
40
+ </td>
41
+
42
+ </tr>
43
+
44
+
45
+ </tbody>
46
+ </table>
@@ -0,0 +1,24 @@
1
+ <html>
2
+
3
+ <head>
4
+ <style>
5
+ body { background-color: #fff; color: #333; }
6
+ body, p, ol, ul, td {
7
+ font-family: verdana, arial, helvetica, sans-serif;
8
+ font-size: 16px;
9
+ line-height: 18px;
10
+ }
11
+ a { color: #000; }
12
+ a:visited { color: #666; }
13
+ a:hover { color: #fff; background-color:#000; }
14
+ </style>
15
+
16
+ <title>The Jenkins Status Tool</title>
17
+ </head>
18
+
19
+ <body>
20
+ <div class = "container">
21
+ <%= yield %>
22
+ </div>
23
+ </body>
24
+ </html>
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jenkins-status-tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eran Barak Levi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: &70325820167340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70325820167340
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70325820166820 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70325820166820
36
+ description: JenkinsStatusTool - get jenkins status
37
+ email: eran@kontera.com
38
+ executables:
39
+ - jenkins-status-tool
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - README.markdown
44
+ - Rakefile
45
+ - bin/jenkins-status-tool
46
+ - lib/jenkins-status-tool/config.rb
47
+ - lib/jenkins-status-tool/jenkins-broker.rb
48
+ - lib/jenkins-status-tool/jenkins-project.rb
49
+ - lib/jenkins-status-tool/runner.rb
50
+ - lib/jenkins-status-tool/utils.rb
51
+ - lib/jenkins-status-tool/version.rb
52
+ - lib/jenkins-status-tool/webapp.rb
53
+ - lib/jenkins-status-tool.rb
54
+ - tasks/build.rake
55
+ - tasks/tests.rake
56
+ - public/images/fail.png
57
+ - public/images/inactive.png
58
+ - public/images/pass.png
59
+ - public/images/rcov-example.png
60
+ - public/images/rcov-no-data.png
61
+ - public/images/unknown.png
62
+ - views/index.erb
63
+ - views/layout.erb
64
+ homepage: http://www.kontera.com
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.7
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: jenkins-status-tool
84
+ rubygems_version: 1.8.15
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: JenkinsStatusTool
88
+ test_files: []