servant 0.0.1 → 0.0.2
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/README.md +6 -2
- data/bin/servant +2 -0
- data/lib/servant/ci.rb +2 -2
- data/lib/servant/environment.rb +21 -14
- data/lib/servant/mixin/command.rb +6 -0
- data/lib/servant/mixin/notification.rb +16 -0
- data/lib/servant/version.rb +1 -1
- data/lib/servant/writer/xmlwriter.rb +11 -1
- metadata +4 -3
data/README.md
CHANGED
|
@@ -22,6 +22,7 @@ gem install servant
|
|
|
22
22
|
mkdir Jobs
|
|
23
23
|
cd Jobs
|
|
24
24
|
servant init
|
|
25
|
+
|
|
25
26
|
cat > recipes/first_job.rb <<EOF
|
|
26
27
|
name "first_job"
|
|
27
28
|
description "my first job for jenkins"
|
|
@@ -34,17 +35,17 @@ servant provision
|
|
|
34
35
|
|
|
35
36
|
# Servant Configurations
|
|
36
37
|
|
|
37
|
-
Servant requires
|
|
38
|
+
Servant requires Servantfile on your project directory.
|
|
38
39
|
|
|
39
40
|
````ruby
|
|
40
41
|
Servant::Config.run do | config |
|
|
41
42
|
config.ci.url = "http://localhost:8080"
|
|
42
43
|
|
|
43
44
|
config.ci.cli = "/tmp/moe/servant/jenkins-cli.jar"
|
|
44
|
-
config.ci.cli_options = []
|
|
45
45
|
|
|
46
46
|
# optional (for update config.xml directly)
|
|
47
47
|
config.ci.user = 'daemon'
|
|
48
|
+
config.ci.password = '1234'
|
|
48
49
|
config.ci.home = "/home/Shared/Library/Jenkins"
|
|
49
50
|
|
|
50
51
|
config.ci.jobs :jobs do | jobs |
|
|
@@ -112,6 +113,8 @@ scm_type :git do | repositories |
|
|
|
112
113
|
:branches, "",
|
|
113
114
|
]
|
|
114
115
|
end
|
|
116
|
+
|
|
117
|
+
notification.email ["chobieee@gmail.com"]
|
|
115
118
|
````
|
|
116
119
|
# License
|
|
117
120
|
|
|
@@ -124,3 +127,4 @@ MIT License
|
|
|
124
127
|
* build_params
|
|
125
128
|
* build step
|
|
126
129
|
* Git
|
|
130
|
+
* notification email
|
data/bin/servant
CHANGED
|
@@ -6,6 +6,7 @@ require 'bundler/setup'
|
|
|
6
6
|
require 'nokogiri'
|
|
7
7
|
require 'log4r'
|
|
8
8
|
|
|
9
|
+
require 'uri'
|
|
9
10
|
require 'tempfile'
|
|
10
11
|
|
|
11
12
|
require 'servant/environment'
|
|
@@ -13,6 +14,7 @@ require 'servant/config'
|
|
|
13
14
|
require 'servant/ci'
|
|
14
15
|
require 'servant/jobcollections'
|
|
15
16
|
require 'servant/mixin/trigger'
|
|
17
|
+
require 'servant/mixin/notification'
|
|
16
18
|
require 'servant/mixin/command'
|
|
17
19
|
require 'servant/mixin/command/config'
|
|
18
20
|
require 'servant/mixin/log_rotator'
|
data/lib/servant/ci.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
module Servant
|
|
2
2
|
class CI
|
|
3
|
-
attr_accessor :home, :user, :
|
|
3
|
+
attr_accessor :home, :user, :password, :cli, :url
|
|
4
4
|
|
|
5
5
|
def initialize
|
|
6
6
|
@home = ""
|
|
7
7
|
@user = ""
|
|
8
|
+
@password = ""
|
|
8
9
|
@cli = ""
|
|
9
10
|
@url = ""
|
|
10
|
-
@cli_options = []
|
|
11
11
|
@jobs = Servant::JobCollections.new
|
|
12
12
|
end
|
|
13
13
|
|
data/lib/servant/environment.rb
CHANGED
|
@@ -27,20 +27,19 @@ module Servant
|
|
|
27
27
|
|
|
28
28
|
case command
|
|
29
29
|
when "init"
|
|
30
|
-
if FileTest.exists?("
|
|
31
|
-
print "
|
|
30
|
+
if FileTest.exists?("Servantfile")
|
|
31
|
+
print "Servantfile exists."
|
|
32
32
|
exit(-1)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
file = open("
|
|
35
|
+
file = open("Servantfile","w")
|
|
36
36
|
file.write <<'EOF'
|
|
37
37
|
Servant::Config.run do | config |
|
|
38
38
|
config.ci.url = "http://localhost:8080"
|
|
39
39
|
|
|
40
40
|
config.ci.user = 'daemon'
|
|
41
|
-
config.ci.
|
|
41
|
+
config.ci.password = ''
|
|
42
42
|
config.ci.home = "/home/Shared/Library/Jenkins"
|
|
43
|
-
config.ci.cli_options = []
|
|
44
43
|
|
|
45
44
|
config.ci.jobs :jobs do | jobs |
|
|
46
45
|
jobs.path = "recipes"
|
|
@@ -55,7 +54,7 @@ EOF
|
|
|
55
54
|
|
|
56
55
|
Dir::mkdir("./recipes")
|
|
57
56
|
when "list"
|
|
58
|
-
config = eval IO.read(File.join(Dir.pwd, "
|
|
57
|
+
config = eval IO.read(File.join(Dir.pwd, "Servantfile"))
|
|
59
58
|
recipes = config.get_recipe
|
|
60
59
|
print "loaded configurations:\n"
|
|
61
60
|
|
|
@@ -63,7 +62,7 @@ EOF
|
|
|
63
62
|
print " #{name}\n"
|
|
64
63
|
end
|
|
65
64
|
when "show"
|
|
66
|
-
config = eval IO.read(File.join(Dir.pwd, "
|
|
65
|
+
config = eval IO.read(File.join(Dir.pwd, "Servantfile"))
|
|
67
66
|
|
|
68
67
|
print "HOME: " + config.ci.home + "\n"
|
|
69
68
|
print "USER: " + config.ci.user + "\n"
|
|
@@ -72,7 +71,7 @@ EOF
|
|
|
72
71
|
|
|
73
72
|
exit
|
|
74
73
|
when "provision"
|
|
75
|
-
config = eval IO.read(File.join(Dir.pwd, "
|
|
74
|
+
config = eval IO.read(File.join(Dir.pwd, "Servantfile"))
|
|
76
75
|
recipes = config.get_recipe
|
|
77
76
|
recipes.each do |name, cfg|
|
|
78
77
|
@logger.info "processing `#{name}`..."
|
|
@@ -82,11 +81,19 @@ EOF
|
|
|
82
81
|
tmp.write xmldata
|
|
83
82
|
tmp.close()
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
if
|
|
87
|
-
|
|
84
|
+
# set password and user
|
|
85
|
+
if config.ci.user.size && config.ci.password.size
|
|
86
|
+
auth = "#{config.ci.user}:#{config.ci.password}"
|
|
88
87
|
else
|
|
89
|
-
|
|
88
|
+
auth = ""
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
encoded_name = URI.encode(cfg.fetch(:name))
|
|
92
|
+
`curl -s -f #{auth} -X GET #{config.ci.url}/job/#{encoded_name}/config.xml 2>&1 > /dev/null`
|
|
93
|
+
if $?.exitstatus == 22
|
|
94
|
+
`curl -s #{auth} -f -X POST #{config.ci.url}/createItem?name=#{encoded_name} --data-binary "@#{tmp.path}" -H "Content-Type: text/xml"`
|
|
95
|
+
else
|
|
96
|
+
`curl -s #{auth} -f -X POST #{config.ci.url}/job/#{encoded_name}/config.xml --data-binary "@#{tmp.path}" -H "Content-Type: text/xml"`
|
|
90
97
|
end
|
|
91
98
|
|
|
92
99
|
if $?.exitstatus == 0
|
|
@@ -97,8 +104,8 @@ EOF
|
|
|
97
104
|
|
|
98
105
|
end
|
|
99
106
|
when "reload"
|
|
100
|
-
config = eval IO.read(File.join(Dir.pwd, "
|
|
101
|
-
|
|
107
|
+
config = eval IO.read(File.join(Dir.pwd, "Servantfile"))
|
|
108
|
+
`curl -s #{auth} -f -X GET #{config.ci.url}/reload 2>&1 > /dev/null`
|
|
102
109
|
else
|
|
103
110
|
show_help
|
|
104
111
|
end
|
|
@@ -9,9 +9,11 @@ module Servant
|
|
|
9
9
|
def get_binding
|
|
10
10
|
trigger = Trigger.new
|
|
11
11
|
log_rotator = LogRotator.new
|
|
12
|
+
notification = Notification.new
|
|
12
13
|
|
|
13
14
|
@trigger = trigger
|
|
14
15
|
@log_rotator = log_rotator
|
|
16
|
+
@notification = notification
|
|
15
17
|
|
|
16
18
|
binding
|
|
17
19
|
end
|
|
@@ -28,6 +30,10 @@ module Servant
|
|
|
28
30
|
if @log_rotator.has_config
|
|
29
31
|
@@config[:log_rotator] = @log_rotator
|
|
30
32
|
end
|
|
33
|
+
|
|
34
|
+
if @notification.has_config
|
|
35
|
+
@@config[:notification] = @notification
|
|
36
|
+
end
|
|
31
37
|
|
|
32
38
|
@@configs[name] = @@config
|
|
33
39
|
@@config = {}
|
data/lib/servant/version.rb
CHANGED
|
@@ -184,7 +184,17 @@ module Servant
|
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
-
project.publishers
|
|
187
|
+
project.publishers do | pub |
|
|
188
|
+
if config.fetch(:notification,nil)
|
|
189
|
+
mail = config.fetch(:notification)
|
|
190
|
+
pub.send(:"hudson.tasks.Mailer") do |mailer|
|
|
191
|
+
mailer.recipients mail.addresses.join " "
|
|
192
|
+
mailer.dontNotifyEveryUnstableBuild false
|
|
193
|
+
mailer.sendToIndividuals true
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
188
198
|
project.buildWrappers nil
|
|
189
199
|
end
|
|
190
200
|
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 0.0.
|
|
8
|
+
- 2
|
|
9
|
+
version: 0.0.2
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Shuhei Tanuma
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2012-03-
|
|
17
|
+
date: 2012-03-12 00:00:00 +09:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies: []
|
|
20
20
|
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- lib/servant/mixin/command.rb
|
|
43
43
|
- lib/servant/mixin/command/config.rb
|
|
44
44
|
- lib/servant/mixin/log_rotator.rb
|
|
45
|
+
- lib/servant/mixin/notification.rb
|
|
45
46
|
- lib/servant/mixin/trigger.rb
|
|
46
47
|
- lib/servant/version.rb
|
|
47
48
|
- lib/servant/writer/xmlwriter.rb
|