jenkins_job 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +12 -0
- data/lib/jenkins_job/cli.rb +12 -9
- data/lib/jenkins_job/version.rb +1 -1
- data/test/cli_test.rb +47 -22
- data/test/project_test.rb +21 -20
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -21,6 +21,12 @@ new project named foo_production testing the production branch.
|
|
21
21
|
Note well: the command must be executed within the directory containing
|
22
22
|
Jenkins' jobs, which is <jenkins_home>/jobs.
|
23
23
|
|
24
|
+
You can also clone multiple projects at the same time:
|
25
|
+
jenkins_job clone foo_master bar_master --original_branch master --new_branch production
|
26
|
+
|
27
|
+
Taking advantage of shell globbing you can even do:
|
28
|
+
jenkins_job clone *_master --original_branch master --new_branch production
|
29
|
+
|
24
30
|
== Other features
|
25
31
|
jenkins_job can help you in other ways.
|
26
32
|
|
@@ -44,3 +50,9 @@ Just execute this command:
|
|
44
50
|
Now the bar_master project will have the irc notifications turned on and
|
45
51
|
configured like foo_master.
|
46
52
|
|
53
|
+
You can also copy a setting to multiple projects at the same time:
|
54
|
+
jenkins_job copy_setting hudson.plugins.ircbot.IrcPublisher foo_master foo_production bar_master
|
55
|
+
|
56
|
+
Taking advantage of shell globbing you can even do:
|
57
|
+
jenkins_job copy_setting hudson.plugins.ircbot.IrcPublisher foo_master bar*
|
58
|
+
|
data/lib/jenkins_job/cli.rb
CHANGED
@@ -60,19 +60,22 @@ module JenkinsJob
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
desc "copy_setting SOURCE_PROJECT SETTING_NAME DEST_PROJECT",
|
64
|
-
"Copy SETTING_NAME from SOURCE_PROJECT to
|
65
|
-
def copy_setting source_project, setting_name, dest_project
|
63
|
+
desc "copy_setting SOURCE_PROJECT SETTING_NAME DEST_PROJECT [DEST_PROJECT, ...]",
|
64
|
+
"Copy SETTING_NAME from SOURCE_PROJECT to the specified destination projects"
|
65
|
+
def copy_setting source_project, setting_name, *dest_project
|
66
66
|
source = Project.new(source_project)
|
67
|
-
dest = Project.new(dest_project)
|
68
|
-
|
69
67
|
setting = source.setting(setting_name)
|
70
68
|
if setting.nil?
|
71
|
-
say
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
say("#{source_project} doesn't contain the specified setting", :red)
|
70
|
+
Kernel::exit(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
dest_project.each do |p|
|
74
|
+
dest = Project.new(p)
|
75
|
+
dest.update_setting(setting_name, setting)
|
76
|
+
say("#{setting_name} copied to #{p}", :green)
|
75
77
|
end
|
76
78
|
end
|
79
|
+
|
77
80
|
end
|
78
81
|
end
|
data/lib/jenkins_job/version.rb
CHANGED
data/test/cli_test.rb
CHANGED
@@ -75,6 +75,7 @@ class CliTest < Test::Unit::TestCase
|
|
75
75
|
|
76
76
|
FakeFS.activate!
|
77
77
|
FakeFS::FileSystem.clear
|
78
|
+
|
78
79
|
FileUtils.mkdir_p 'foo_master'
|
79
80
|
File.open('foo_master/config.xml', 'w') do |file|
|
80
81
|
file.write @source_xml
|
@@ -111,7 +112,7 @@ class CliTest < Test::Unit::TestCase
|
|
111
112
|
|
112
113
|
context 'force overwrite enabled' do
|
113
114
|
should 'not prompt user when force is set to true' do
|
114
|
-
|
115
|
+
Thor::Shell::Color.any_instance.expects(:yes?).never
|
115
116
|
|
116
117
|
capture(:stdout) do
|
117
118
|
JenkinsJob::Cli.start(['clone', 'foo_master', '--original_branch',
|
@@ -131,7 +132,7 @@ class CliTest < Test::Unit::TestCase
|
|
131
132
|
context 'force overwrite is not set' do
|
132
133
|
context 'user wants to overwrite' do
|
133
134
|
should 'overwrite the old contents and create the new ones' do
|
134
|
-
|
135
|
+
Thor::Shell::Color.any_instance.expects(:yes?).once.returns(true)
|
135
136
|
capture(:stdout) do
|
136
137
|
JenkinsJob::Cli.start(['clone', 'foo_master', '--original_branch',
|
137
138
|
'master', '--new_branch', 'production'])
|
@@ -147,7 +148,7 @@ class CliTest < Test::Unit::TestCase
|
|
147
148
|
|
148
149
|
context "user doesn't want to overwrite" do
|
149
150
|
should 'preserve the old contents' do
|
150
|
-
|
151
|
+
Thor::Shell::Color.any_instance.expects(:yes?).once.returns(false)
|
151
152
|
capture(:stdout) do
|
152
153
|
JenkinsJob::Cli.start(['clone', 'foo_master', '--original_branch',
|
153
154
|
'master', '--new_branch', 'production'])
|
@@ -170,33 +171,57 @@ class CliTest < Test::Unit::TestCase
|
|
170
171
|
source = mock()
|
171
172
|
source.expects(:setting).with('irc_bot').once.returns(nil)
|
172
173
|
|
173
|
-
|
174
|
-
|
174
|
+
JenkinsJob::Project.expects(:new).once.returns(source)
|
175
|
+
Thor::Shell::Color.any_instance.expects(:say)\
|
176
|
+
.with(is_a(String), :red).once
|
177
|
+
Kernel.expects(:exit).with(1).raises('exiting')
|
175
178
|
|
176
|
-
|
177
|
-
|
179
|
+
assert_raises RuntimeError do
|
180
|
+
capture(:stdout) do
|
181
|
+
JenkinsJob::Cli.start(['copy_setting', 'foo_master', 'irc_bot',
|
182
|
+
'foo_production'])
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
178
186
|
|
179
|
-
|
180
|
-
|
181
|
-
|
187
|
+
context 'existing setting' do
|
188
|
+
should 'handle a single destination' do
|
189
|
+
source = mock()
|
190
|
+
source.expects(:setting).with('irc_bot').once.returns('foo')
|
191
|
+
|
192
|
+
dest = mock()
|
193
|
+
dest.expects(:update_setting).with('irc_bot', 'foo').once
|
194
|
+
|
195
|
+
JenkinsJob::Project.expects(:new).twice.returns(source).then.returns(dest)
|
196
|
+
Thor::Shell::Color.any_instance.expects(:say)\
|
197
|
+
.with(is_a(String), :green) .once
|
198
|
+
capture(:stdout) do
|
199
|
+
JenkinsJob::Cli.start(['copy_setting', 'foo_master', 'irc_bot',
|
200
|
+
'foo_production'])
|
201
|
+
end
|
182
202
|
end
|
183
203
|
|
184
|
-
|
204
|
+
should 'handle multiple destination projects' do
|
205
|
+
source = mock()
|
206
|
+
source.expects(:setting).with('irc_bot').once.returns('foo')
|
185
207
|
|
186
|
-
|
187
|
-
|
188
|
-
source.expects(:setting).with('irc_bot').once.returns('foo')
|
208
|
+
dest_foo_prod = mock()
|
209
|
+
dest_foo_prod.expects(:update_setting).with('irc_bot', 'foo').once
|
189
210
|
|
190
|
-
|
191
|
-
|
211
|
+
dest_bar_prod = mock()
|
212
|
+
dest_bar_prod.expects(:update_setting).with('irc_bot', 'foo').once
|
192
213
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
214
|
+
JenkinsJob::Project.expects(:new).times(3)\
|
215
|
+
.returns(source).then\
|
216
|
+
.returns(dest_foo_prod).then\
|
217
|
+
.returns(dest_bar_prod)
|
218
|
+
Thor::Shell::Color.any_instance.expects(:say)\
|
219
|
+
.with(is_a(String), :green).twice
|
220
|
+
capture(:stdout) do
|
221
|
+
JenkinsJob::Cli.start(['copy_setting', 'foo_master', 'irc_bot',
|
222
|
+
'foo_production', 'bar_production'])
|
223
|
+
end
|
198
224
|
end
|
199
225
|
end
|
200
|
-
|
201
226
|
end
|
202
227
|
end
|
data/test/project_test.rb
CHANGED
@@ -87,26 +87,27 @@ class ProjectTest < Test::Unit::TestCase
|
|
87
87
|
assert_nil actual
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
90
|
+
context 'update an existing setting by overwriting it' do
|
91
|
+
should 'handle simple nodes' do
|
92
|
+
node = REXML::Element.new 'disabled'
|
93
|
+
node.text = 'true'
|
94
|
+
|
95
|
+
assert @project.enabled?
|
96
|
+
@project.update_setting 'disabled', node
|
97
|
+
assert @project.disabled?
|
98
|
+
end
|
99
|
+
|
100
|
+
should 'handle complex nodes' do
|
101
|
+
parent = REXML::Element.new 'foobar_parent'
|
102
|
+
node = REXML::Element.new 'foobar'
|
103
|
+
node.text = 'hello world'
|
104
|
+
parent << node
|
105
|
+
|
106
|
+
@project.update_setting 'foobar_parent', parent
|
107
|
+
actual_node = @project.setting 'foobar_parent/foobar'
|
108
|
+
assert_equal 1, @project.setting('foobar_parent').size
|
109
|
+
assert_equal node.text, actual_node.text
|
110
|
+
end
|
110
111
|
end
|
111
112
|
|
112
113
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Flavio Castelli
|