jenkinsgrowler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/jenkinsgrowler +3 -0
- data/lib/argumentsparser.rb +65 -0
- data/lib/jenkinsgrowler.rb +77 -0
- metadata +64 -0
data/bin/jenkinsgrowler
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module JenkinsGrowler
|
4
|
+
|
5
|
+
class ArgumentsParser
|
6
|
+
|
7
|
+
def parse(args)
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
optparse = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: jenkinsgrowler [options]"
|
12
|
+
|
13
|
+
options[:server_url] = nil
|
14
|
+
options[:jobs] = []
|
15
|
+
options[:poll_interval] = 60
|
16
|
+
options[:username] = nil
|
17
|
+
options[:password] = nil
|
18
|
+
options[:timezone] = "+0530"
|
19
|
+
|
20
|
+
|
21
|
+
opts.on("-s","--server SERVER_URL","URL of the jenkins server") do |url|
|
22
|
+
options[:server_url] = url
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-j","--jobs JOBS","Comma separated jobs names") do |jobs|
|
26
|
+
if (jobs.length > 0) then
|
27
|
+
jobs.split(',').each do |job|
|
28
|
+
options[:jobs] << job.strip()
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-i","--interval INTEVAL","Polling interval in seconds. Default (60 seconds)") do |interval|
|
34
|
+
options[:poll_interval] = interval.to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-u","--user USERNAME","Username for basic authentication") do |username|
|
38
|
+
options[:username] = username
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on("-p","--password PASSWORD","Password for basic authentication") do |password|
|
42
|
+
options[:password] = password
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("-t","--timezone TIMEZONE", "Server's timezone. Default (+0530)") do |timezone|
|
46
|
+
options[:timezone] = timezone
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on( "-h", "--help", "Displays help message" ) do
|
50
|
+
puts opts
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
optparse.parse!(args)
|
56
|
+
|
57
|
+
if(options[:server_url] == nil || options[:jobs].length == 0)
|
58
|
+
puts optparse
|
59
|
+
exit(-1)
|
60
|
+
end
|
61
|
+
|
62
|
+
options
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'date'
|
6
|
+
require 'argumentsparser'
|
7
|
+
|
8
|
+
options = JenkinsGrowler::ArgumentsParser.new.parse(ARGV)
|
9
|
+
|
10
|
+
$ciBaseUrl = options[:server_url]
|
11
|
+
$jobs = options[:jobs]
|
12
|
+
$interval = options[:poll_interval]
|
13
|
+
$username = options[:username]
|
14
|
+
$password = options[:password]
|
15
|
+
$timezone = options[:timezone]
|
16
|
+
|
17
|
+
$jobRuns = Hash.new
|
18
|
+
|
19
|
+
def last_build_output(job)
|
20
|
+
uri = URI.parse("#{$ciBaseUrl}/job/#{job}/lastBuild/api/json")
|
21
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
22
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
23
|
+
if ($username !=nil && $password != nil) then
|
24
|
+
request.basic_auth($username, $password)
|
25
|
+
end
|
26
|
+
|
27
|
+
res = http.request(request)
|
28
|
+
JSON.parse res.body
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def changed_recently(buildTime, job)
|
33
|
+
buildRunTime = DateTime.strptime("#{buildTime}#{$timezone}", '%Y-%m-%d_%H-%M-%S%z')
|
34
|
+
|
35
|
+
if $jobRuns[job] == nil then
|
36
|
+
$jobRuns[job] = buildRunTime
|
37
|
+
return false
|
38
|
+
end
|
39
|
+
|
40
|
+
if buildRunTime > $jobRuns[job] then
|
41
|
+
$jobRuns[job] = buildRunTime
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
return false
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def build_status(job)
|
49
|
+
buildOutput = last_build_output job
|
50
|
+
puts(buildOutput)
|
51
|
+
building = buildOutput['building']
|
52
|
+
buildTime = buildOutput['id']
|
53
|
+
duration = buildOutput['duration']
|
54
|
+
|
55
|
+
if building or !changed_recently(buildTime, job) then
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
59
|
+
result = buildOutput['result']
|
60
|
+
description = buildOutput['fullDisplayName']
|
61
|
+
url = buildOutput['url']
|
62
|
+
|
63
|
+
comments = ''
|
64
|
+
buildOutput['changeSet']['items'].each do |item|
|
65
|
+
comments += item['comment']
|
66
|
+
end
|
67
|
+
|
68
|
+
%x[ growlnotify -t "#{result}" -m "#{description}\n#{comments}" ]
|
69
|
+
end
|
70
|
+
|
71
|
+
while true do
|
72
|
+
$jobs.each do |job|
|
73
|
+
build_status job
|
74
|
+
end
|
75
|
+
|
76
|
+
sleep $interval
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkinsgrowler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Srivatsa Katta
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mocha
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.12.3
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.12.3
|
30
|
+
description: Jenkinsgrowler is a notifier for jenkins jobs
|
31
|
+
email: vatsa.katta@gmail.com
|
32
|
+
executables:
|
33
|
+
- jenkinsgrowler
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/jenkinsgrowler.rb
|
38
|
+
- lib/argumentsparser.rb
|
39
|
+
- bin/jenkinsgrowler
|
40
|
+
homepage: http://github.com/katta/jenkinsgrowler
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.25
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Growl notifier for jenkins jobs
|
64
|
+
test_files: []
|