jenkins-branching 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +11 -1
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/jenkins-branching.gemspec +13 -5
- data/lib/jenkins-branching.rb +1 -1
- data/lib/tasks/git_task.rb +9 -0
- data/lib/tasks/jenkins_branching.rake +8 -226
- data/lib/tasks/jenkins_task.rb +41 -0
- data/lib/tasks/jenkins_task_configure.rb +41 -0
- data/lib/tasks/jenkins_task_manage_jobs.rb +121 -0
- data/spec/lib/tasks/jenkins_task_configure_spec.rb +66 -0
- data/spec/spec_helper.rb +17 -0
- metadata +23 -4
- data/test/helper.rb +0 -18
- data/test/test_jenkins-branching.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66cef882a986471a73654f2ef6f54a33493c883f
|
4
|
+
data.tar.gz: bc1c58c61537fe5246ea6657662d415e6e6cbc91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2869755d7a3a747e93022a42a42298b80952d8709a02bb034ff4decdc8fa07d92445047b6a2c17a2798cec28e2a13ad4034fffd3535e41c97add4b83c1d49d5b
|
7
|
+
data.tar.gz: b45d706aeb17bea4b4853796d6d564a6da10991dd13c250619c52f230e43151cfa699dd6a6d63a8c21505421dcbc00df19cae0de3d6899f54cea6cdbfbc89622
|
data/.rspec
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -14,6 +14,7 @@ GEM
|
|
14
14
|
specs:
|
15
15
|
addressable (2.3.5)
|
16
16
|
builder (3.2.2)
|
17
|
+
diff-lcs (1.2.5)
|
17
18
|
faraday (0.8.9)
|
18
19
|
multipart-post (~> 1.2.0)
|
19
20
|
git (1.2.6)
|
@@ -36,7 +37,7 @@ GEM
|
|
36
37
|
rake
|
37
38
|
rdoc
|
38
39
|
json (1.8.1)
|
39
|
-
jwt (0.1.
|
40
|
+
jwt (0.1.11)
|
40
41
|
multi_json (>= 1.5)
|
41
42
|
mixlib-shellout (1.3.0)
|
42
43
|
multi_json (1.8.4)
|
@@ -53,6 +54,14 @@ GEM
|
|
53
54
|
rake (10.1.1)
|
54
55
|
rdoc (4.1.1)
|
55
56
|
json (~> 1.4)
|
57
|
+
rspec (2.14.1)
|
58
|
+
rspec-core (~> 2.14.0)
|
59
|
+
rspec-expectations (~> 2.14.0)
|
60
|
+
rspec-mocks (~> 2.14.0)
|
61
|
+
rspec-core (2.14.7)
|
62
|
+
rspec-expectations (2.14.4)
|
63
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
64
|
+
rspec-mocks (2.14.4)
|
56
65
|
terminal-table (1.4.5)
|
57
66
|
thor (0.18.1)
|
58
67
|
|
@@ -65,3 +74,4 @@ DEPENDENCIES
|
|
65
74
|
jenkins_api_client (= 0.15.4)!
|
66
75
|
jeweler
|
67
76
|
rake
|
77
|
+
rspec
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/jenkins-branching.gemspec
CHANGED
@@ -2,21 +2,22 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: jenkins-branching 0.1.
|
5
|
+
# stub: jenkins-branching 0.1.6 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "jenkins-branching"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.6"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.authors = ["Bruno Chauvet"]
|
13
|
-
s.date = "2014-01-
|
13
|
+
s.date = "2014-01-19"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.md"
|
16
16
|
]
|
17
17
|
s.files = [
|
18
18
|
".document",
|
19
19
|
".gemspec",
|
20
|
+
".rspec",
|
20
21
|
"Gemfile",
|
21
22
|
"Gemfile.lock",
|
22
23
|
"README.md",
|
@@ -24,9 +25,13 @@ Gem::Specification.new do |s|
|
|
24
25
|
"VERSION",
|
25
26
|
"jenkins-branching.gemspec",
|
26
27
|
"lib/jenkins-branching.rb",
|
28
|
+
"lib/tasks/git_task.rb",
|
27
29
|
"lib/tasks/jenkins_branching.rake",
|
28
|
-
"
|
29
|
-
"
|
30
|
+
"lib/tasks/jenkins_task.rb",
|
31
|
+
"lib/tasks/jenkins_task_configure.rb",
|
32
|
+
"lib/tasks/jenkins_task_manage_jobs.rb",
|
33
|
+
"spec/lib/tasks/jenkins_task_configure_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
30
35
|
]
|
31
36
|
s.require_paths = ["lib"]
|
32
37
|
s.rubygems_version = "2.1.10"
|
@@ -41,12 +46,14 @@ Gem::Specification.new do |s|
|
|
41
46
|
s.add_runtime_dependency(%q<highline>, [">= 0"])
|
42
47
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
43
48
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
44
50
|
else
|
45
51
|
s.add_dependency(%q<rake>, [">= 0"])
|
46
52
|
s.add_dependency(%q<jenkins_api_client>, ["= 0.15.4"])
|
47
53
|
s.add_dependency(%q<highline>, [">= 0"])
|
48
54
|
s.add_dependency(%q<bundler>, [">= 0"])
|
49
55
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
50
57
|
end
|
51
58
|
else
|
52
59
|
s.add_dependency(%q<rake>, [">= 0"])
|
@@ -54,6 +61,7 @@ Gem::Specification.new do |s|
|
|
54
61
|
s.add_dependency(%q<highline>, [">= 0"])
|
55
62
|
s.add_dependency(%q<bundler>, [">= 0"])
|
56
63
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
data/lib/jenkins-branching.rb
CHANGED
@@ -1,250 +1,32 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
1
|
+
require 'tasks/jenkins_task_configure'
|
2
|
+
require 'tasks/jenkins_task_manage_jobs'
|
3
|
+
require 'tasks/git_task'
|
4
4
|
|
5
5
|
namespace :jenkins do
|
6
6
|
|
7
7
|
desc 'Creates a new jenkins job for a specified branch'
|
8
8
|
task :new_job, :branch do |t, args|
|
9
|
-
|
9
|
+
JenkinsTaskManageJobs.new.create_new_job args[:branch]
|
10
10
|
end
|
11
11
|
|
12
12
|
desc 'Removes a jenkins job for a specified branch'
|
13
13
|
task :delete_job, :branch do |t, args|
|
14
|
-
|
14
|
+
JenkinsTaskManageJobs.new.delete_job args[:branch]
|
15
15
|
end
|
16
16
|
|
17
17
|
desc 'Fetch the current config of a job for the specified branch'
|
18
18
|
task :job_config, :branch do |t, args|
|
19
|
-
|
19
|
+
JenkinsTaskManageJobs.new.get_job_config args[:branch]
|
20
20
|
end
|
21
21
|
|
22
22
|
desc 'Display config required by jenkins tasks'
|
23
23
|
task :show_config do
|
24
|
-
|
24
|
+
JenkinsTaskConfigure.new.show_config
|
25
25
|
end
|
26
26
|
|
27
27
|
desc 'Configure settings required by jenkins tasks'
|
28
28
|
task :configure do
|
29
|
-
|
29
|
+
JenkinsTaskConfigure.new.configure
|
30
30
|
end
|
31
31
|
|
32
32
|
end
|
33
|
-
|
34
|
-
module Jenkins
|
35
|
-
module Rake
|
36
|
-
|
37
|
-
class Task
|
38
|
-
|
39
|
-
def show_config
|
40
|
-
puts "Using configuration file: #{config_file}\n#{config}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def configure
|
44
|
-
puts "Jenkins configuration for #{project}"
|
45
|
-
|
46
|
-
config['git'] = {} unless config['git']
|
47
|
-
config['git']['email'] = add_configuration(config['git']['email'], "Git email", Git::Rake::Task.get_user_email.strip)
|
48
|
-
|
49
|
-
config['jenkins'] = {} unless config['jenkins']
|
50
|
-
config['jenkins']['url'] = add_configuration(config['jenkins']['url'], "Jenkins URL", "https://10.48.0.91")
|
51
|
-
config['jenkins']['ssl'] = add_configuration(config['jenkins']['ssl'], "Use SSL", "true")
|
52
|
-
config['jenkins']['proxy_ip'] = add_configuration(config['jenkins']['proxy_ip'], "Proxy IP", "localhost")
|
53
|
-
config['jenkins']['proxy_port'] = add_configuration(config['jenkins']['proxy_port'], "Proxy port", "3128")
|
54
|
-
config['jenkins']['username'] = add_configuration(config['jenkins']['username'], "Jenkins Username", "")
|
55
|
-
config['jenkins']['password'] = add_configuration(config['jenkins']['password'], "Jenkins Password", "", false)
|
56
|
-
config['jenkins']['restricted_node'] = add_configuration(config['jenkins']['restricted_node'], "Jenkins node", "PaaS-Jenkins-Slave")
|
57
|
-
config['jenkins']['job_prefix'] = add_configuration(config['jenkins']['job_prefix'], "Jonb prefix", "search-test")
|
58
|
-
|
59
|
-
config['s3_options'] = {} unless config['s3_options']
|
60
|
-
config['s3_options']['profile'] = add_configuration(config['s3_options']['profile'], "S3 Profile", "JenkinsUser")
|
61
|
-
config['s3_options']['bucket'] = add_configuration(config['s3_options']['bucket'], "S3 Bucket", "vha-repository")
|
62
|
-
config['s3_options']['region'] = add_configuration(config['s3_options']['region'], "S3 Region", "AP_SOUTHEAST_2")
|
63
|
-
|
64
|
-
File.open("#{config_file}", "w") do |file|
|
65
|
-
file.write config.to_yaml
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
def create_new_job(branch)
|
71
|
-
configure unless config
|
72
|
-
|
73
|
-
job_name = job(branch)
|
74
|
-
puts "Creating new job #{job_name}"
|
75
|
-
|
76
|
-
fail_on_args_error(branch)
|
77
|
-
fail_on_missing_remote_branch(branch)
|
78
|
-
fail_on_existing_job(job_name)
|
79
|
-
|
80
|
-
rake_spec = "\nbundle exec rake spec"
|
81
|
-
rake_jasmine = " && bundle exec rake jasmine"
|
82
|
-
rake_cukes = " && bundle exec rake cukes"
|
83
|
-
tar_file_name = "#{project}-#{branch}-${BUILD_NUMBER}.tar.gz"
|
84
|
-
tar_file = "&& tar cvfz #{tar_file_name} --exclude-from=tarignore * .[a-zA-Z0-9]*"
|
85
|
-
job_hash = {
|
86
|
-
:name => job_name,
|
87
|
-
:restricted_node => "#{config['jenkins']['restricted_node']}",
|
88
|
-
:scm_provider => "git",
|
89
|
-
:scm_url => "git@github.com:VodafoneAustralia/#{project}.git",
|
90
|
-
:scm_branch => branch,
|
91
|
-
:shell_command => "
|
92
|
-
#!/bin/bash -e
|
93
|
-
export TERM=xterm
|
94
|
-
[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"
|
95
|
-
bundle package --all
|
96
|
-
RAILS_ENV=test bundle exec rake
|
97
|
-
|
98
|
-
bash script/createManifest
|
99
|
-
cd ${WORKSPACE}/../
|
100
|
-
rm -f ${JOB_NAME}.tar.gz
|
101
|
-
tar --exclude=.git --exclude=lib/load_test --exclude=feature --exclude=coverage --exclude=log --exclude=build --exclude=spec -zcf ${JOB_NAME}.tar.gz ${JOB_NAME}
|
102
|
-
aws s3api put-object --bucket vha-repository --key releases/paas/search-app/${JOB_NAME}-${BUILD_NUMBER}.tar.gz --region ap-southeast-2 --body ${JOB_NAME}.tar.gz",
|
103
|
-
:scm_branch => branch,
|
104
|
-
:scm_trigger => '*/5 * * * *',
|
105
|
-
:build_wrappers_xvfb => true,
|
106
|
-
:build_wrappers_ansicolor => true,
|
107
|
-
:build_wrappers_mask_password => true,
|
108
|
-
:log_rotator => true
|
109
|
-
}
|
110
|
-
|
111
|
-
s3_options = config['s3_options'].merge({tar_file: tar_file_name})
|
112
|
-
git_options = { fast_remote_polling: true }
|
113
|
-
job_hash.merge!(s3_artifact_publisher: s3_options, git: git_options)
|
114
|
-
client.job.create_freestyle job_hash
|
115
|
-
|
116
|
-
add_email_notification(job_name)
|
117
|
-
|
118
|
-
puts "Done. New job #{job_name} created with SUCCESS"
|
119
|
-
end
|
120
|
-
|
121
|
-
def delete_job(branch)
|
122
|
-
job_name = job(branch)
|
123
|
-
puts "Deleting job #{job_name}"
|
124
|
-
|
125
|
-
fail_on_args_error(branch)
|
126
|
-
fail_on_missing_remote_branch(branch)
|
127
|
-
fail_on_non_existing_job(job_name)
|
128
|
-
|
129
|
-
client.job.delete job_name
|
130
|
-
|
131
|
-
puts "Done. Job #{job_name} has been deleted"
|
132
|
-
end
|
133
|
-
|
134
|
-
def get_job_config(branch)
|
135
|
-
job_name = job(branch)
|
136
|
-
puts "Fetching configuration of job: #{job_name}"
|
137
|
-
|
138
|
-
fail_on_args_error(branch)
|
139
|
-
fail_on_missing_remote_branch(branch)
|
140
|
-
fail_on_non_existing_job(job_name)
|
141
|
-
|
142
|
-
puts "Done.\n#{client.job.get_config(job_name)}"
|
143
|
-
end
|
144
|
-
|
145
|
-
private
|
146
|
-
|
147
|
-
def client
|
148
|
-
@client ||= begin
|
149
|
-
server_url = config['jenkins']['url']
|
150
|
-
proxy_ip = config['jenkins']['proxy_ip']
|
151
|
-
proxy_port = config['jenkins']['proxy_port']
|
152
|
-
|
153
|
-
if proxy_ip.to_s == ''
|
154
|
-
puts "Connecting to Jenkins server #{server_url}"
|
155
|
-
JenkinsApi::Client.new(
|
156
|
-
:server_url => server_url,
|
157
|
-
:username => config['jenkins']['username'],
|
158
|
-
:password => config['jenkins']['password'],
|
159
|
-
:ssl => config['jenkins']['ssl'],
|
160
|
-
:timeout => 300,
|
161
|
-
:log_level => Logger::WARN
|
162
|
-
)
|
163
|
-
else
|
164
|
-
puts "Connecting to Jenkins server #{server_url} via proxy #{proxy_ip}:#{proxy_port}"
|
165
|
-
JenkinsApi::Client.new(
|
166
|
-
:server_url => server_url,
|
167
|
-
:username => config['jenkins']['username'],
|
168
|
-
:password => config['jenkins']['password'],
|
169
|
-
:ssl => config['jenkins']['ssl'],
|
170
|
-
:timeout => 300,
|
171
|
-
:proxy_ip => proxy_ip,
|
172
|
-
:proxy_port => proxy_port,
|
173
|
-
:log_level => Logger::WARN
|
174
|
-
)
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def add_email_notification(job_name)
|
181
|
-
user_email_address = config['git']['email']
|
182
|
-
unless user_email_address.empty?
|
183
|
-
client.job.add_email_notification(:name => job_name, :notification_email => user_email_address)
|
184
|
-
puts "Build failures will be emailed to #{user_email_address}"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
def config
|
189
|
-
@config ||= (File.exists?(config_file) ? YAML::load(File.open(config_file)) : {})
|
190
|
-
end
|
191
|
-
|
192
|
-
def config_file
|
193
|
-
dirname = File.dirname("#{ENV['HOME']}/.#{project}/#{project}.yml")
|
194
|
-
Dir.mkdir(dirname) unless Dir.exist?(dirname)
|
195
|
-
@config_file ||= "#{dirname}/#{project}.yml"
|
196
|
-
end
|
197
|
-
|
198
|
-
def add_configuration(current_value, label, default, echo=true)
|
199
|
-
current_value = default if current_value.to_s == ''
|
200
|
-
value = (ask("#{label} (#{echo ? current_value : '******'}): ") { |q| q.echo = echo }).to_s
|
201
|
-
return value.empty? ? current_value : value
|
202
|
-
end
|
203
|
-
|
204
|
-
def fail_on_args_error(branch)
|
205
|
-
fail 'Please specify a branch name, e.g. rake jenkins:new_job[SS-123]' if branch.to_s == ''
|
206
|
-
end
|
207
|
-
|
208
|
-
def fail_on_missing_remote_branch(branch)
|
209
|
-
fail "No remote branch found named #{branch}, please create one first" unless Git::Rake::Task.remote_branch_exists?(branch)
|
210
|
-
end
|
211
|
-
|
212
|
-
def fail_on_existing_job(job)
|
213
|
-
fail "Job #{job} already exists, please provide a unique job name" if client.job.exists?(job)
|
214
|
-
end
|
215
|
-
|
216
|
-
def fail_on_non_existing_job(job)
|
217
|
-
fail "Job #{job} does not exist" unless client.job.exists?(job)
|
218
|
-
end
|
219
|
-
|
220
|
-
def project
|
221
|
-
@project ||= File.basename(Dir.getwd)
|
222
|
-
end
|
223
|
-
|
224
|
-
def job(branch)
|
225
|
-
@job ||= "#{config['jenkins']['job_prefix']}-#{project}-#{branch}"
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
module Git
|
235
|
-
module Rake
|
236
|
-
|
237
|
-
class Task
|
238
|
-
|
239
|
-
def self.get_user_email
|
240
|
-
`git config --get user.email`
|
241
|
-
end
|
242
|
-
|
243
|
-
def self.remote_branch_exists?(branch)
|
244
|
-
`git branch -r`.each_line.count {|l| l.include?(branch)} > 0
|
245
|
-
end
|
246
|
-
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'jenkins_api_client'
|
3
|
+
require 'highline/import'
|
4
|
+
|
5
|
+
require 'tasks/git_task'
|
6
|
+
|
7
|
+
class JenkinsTask
|
8
|
+
def fail_on_args_error(branch)
|
9
|
+
fail 'Please specify a branch name, e.g. rake jenkins:new_job[SS-123]' if branch.to_s == ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def fail_on_missing_remote_branch(branch)
|
13
|
+
fail "No remote branch found named #{branch}, please create one first" unless GitTask.remote_branch_exists?(branch)
|
14
|
+
end
|
15
|
+
|
16
|
+
def fail_on_existing_job(job)
|
17
|
+
fail "Job #{job} already exists, please provide a unique job name" if client.job.exists?(job)
|
18
|
+
end
|
19
|
+
|
20
|
+
def fail_on_non_existing_job(job)
|
21
|
+
fail "Job #{job} does not exist" unless client.job.exists?(job)
|
22
|
+
end
|
23
|
+
|
24
|
+
def project
|
25
|
+
@project ||= File.basename(Dir.getwd)
|
26
|
+
end
|
27
|
+
|
28
|
+
def job(branch)
|
29
|
+
@job ||= "#{config['jenkins']['job_prefix']}-#{project}-#{branch}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def config
|
33
|
+
@config ||= (File.exists?(config_file) ? YAML::load(File.open(config_file)) : {})
|
34
|
+
end
|
35
|
+
|
36
|
+
def config_file
|
37
|
+
dirname = File.dirname("#{ENV['HOME']}/.#{project}/#{project}.yml")
|
38
|
+
Dir.mkdir(dirname) unless Dir.exist?(dirname)
|
39
|
+
@config_file ||= "#{dirname}/#{project}.yml"
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'tasks/jenkins_task'
|
2
|
+
|
3
|
+
class JenkinsTaskConfigure < JenkinsTask
|
4
|
+
def show_config
|
5
|
+
puts "Using configuration file: #{config_file}\n#{config.to_yaml}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def configure
|
9
|
+
puts "Jenkins configuration for #{project}"
|
10
|
+
|
11
|
+
config['git'] = {} unless config['git']
|
12
|
+
config['git']['email'] = add_configuration(config['git']['email'], "Git email", GitTask.get_user_email.strip)
|
13
|
+
|
14
|
+
config['jenkins'] = {} unless config['jenkins']
|
15
|
+
config['jenkins']['url'] = add_configuration(config['jenkins']['url'], "Jenkins URL", "https://10.48.0.91")
|
16
|
+
config['jenkins']['ssl'] = add_configuration(config['jenkins']['ssl'], "Use SSL", "true")
|
17
|
+
config['jenkins']['proxy_ip'] = add_configuration(config['jenkins']['proxy_ip'], "Proxy IP", "localhost")
|
18
|
+
config['jenkins']['proxy_port'] = add_configuration(config['jenkins']['proxy_port'], "Proxy port", "3128")
|
19
|
+
config['jenkins']['username'] = add_configuration(config['jenkins']['username'], "Jenkins Username", "")
|
20
|
+
config['jenkins']['password'] = add_configuration(config['jenkins']['password'], "Jenkins Password", "", false)
|
21
|
+
config['jenkins']['restricted_node'] = add_configuration(config['jenkins']['restricted_node'], "Jenkins node", "PaaS-Jenkins-Slave")
|
22
|
+
config['jenkins']['job_prefix'] = add_configuration(config['jenkins']['job_prefix'], "Jonb prefix", "search-test")
|
23
|
+
|
24
|
+
config['s3_options'] = {} unless config['s3_options']
|
25
|
+
config['s3_options']['profile'] = add_configuration(config['s3_options']['profile'], "S3 Profile", "Devops-Prod-Build")
|
26
|
+
config['s3_options']['bucket'] = add_configuration(config['s3_options']['bucket'], "S3 Bucket", "vha-repository")
|
27
|
+
config['s3_options']['region'] = add_configuration(config['s3_options']['region'], "S3 Region", "AP_SOUTHEAST_2")
|
28
|
+
|
29
|
+
File.open("#{config_file}", "w") do |file|
|
30
|
+
file.write config.to_yaml
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def add_configuration(current_value, label, default, echo=true)
|
37
|
+
current_value = default if current_value.to_s == ''
|
38
|
+
value = (HighLine.ask("#{label} (#{echo ? current_value : '******'}): ") { |q| q.echo = echo }).to_s
|
39
|
+
return value.empty? ? current_value : value
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'tasks/jenkins_task'
|
2
|
+
|
3
|
+
class JenkinsTaskManageJobs < JenkinsTask
|
4
|
+
def create_new_job(branch)
|
5
|
+
configure unless config
|
6
|
+
|
7
|
+
job_name = job(branch)
|
8
|
+
puts "Creating new job #{job_name}"
|
9
|
+
|
10
|
+
fail_on_args_error(branch)
|
11
|
+
fail_on_missing_remote_branch(branch)
|
12
|
+
fail_on_existing_job(job_name)
|
13
|
+
|
14
|
+
rake_spec = "\nbundle exec rake spec"
|
15
|
+
rake_jasmine = " && bundle exec rake jasmine"
|
16
|
+
rake_cukes = " && bundle exec rake cukes"
|
17
|
+
tar_file_name = "#{project}-#{branch}-${BUILD_NUMBER}.tar.gz"
|
18
|
+
tar_file = "&& tar cvfz #{tar_file_name} --exclude-from=tarignore * .[a-zA-Z0-9]*"
|
19
|
+
job_hash = {
|
20
|
+
:name => job_name,
|
21
|
+
:restricted_node => "#{config['jenkins']['restricted_node']}",
|
22
|
+
:scm_provider => "git",
|
23
|
+
:scm_url => "git@github.com:VodafoneAustralia/#{project}.git",
|
24
|
+
:scm_branch => branch,
|
25
|
+
:shell_command => "
|
26
|
+
#!/bin/bash -e
|
27
|
+
export TERM=xterm
|
28
|
+
[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"
|
29
|
+
bundle package --all
|
30
|
+
RAILS_ENV=test bundle exec rake
|
31
|
+
|
32
|
+
bash script/createManifest
|
33
|
+
cd ${WORKSPACE}/../
|
34
|
+
rm -f ${JOB_NAME}.tar.gz
|
35
|
+
tar --exclude=.git --exclude=lib/load_test --exclude=feature --exclude=coverage --exclude=log --exclude=build --exclude=spec -zcf ${JOB_NAME}.tar.gz ${JOB_NAME}
|
36
|
+
aws s3api put-object --bucket vha-repository --key releases/paas/search-app/${JOB_NAME}-${BUILD_NUMBER}.tar.gz --region ap-southeast-2 --body ${JOB_NAME}.tar.gz",
|
37
|
+
:scm_branch => branch,
|
38
|
+
:scm_trigger => '*/5 * * * *',
|
39
|
+
:build_wrappers_xvfb => true,
|
40
|
+
:build_wrappers_ansicolor => true,
|
41
|
+
:build_wrappers_mask_password => true,
|
42
|
+
:log_rotator => true
|
43
|
+
}
|
44
|
+
|
45
|
+
s3_options = config['s3_options'].merge({tar_file: tar_file_name})
|
46
|
+
git_options = { fast_remote_polling: true }
|
47
|
+
job_hash.merge!(s3_artifact_publisher: s3_options, git: git_options)
|
48
|
+
client.job.create_freestyle job_hash
|
49
|
+
|
50
|
+
add_email_notification(job_name)
|
51
|
+
|
52
|
+
puts "Done. New job #{job_name} created with SUCCESS"
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_job(branch)
|
56
|
+
job_name = job(branch)
|
57
|
+
puts "Deleting job #{job_name}"
|
58
|
+
|
59
|
+
fail_on_args_error(branch)
|
60
|
+
fail_on_missing_remote_branch(branch)
|
61
|
+
fail_on_non_existing_job(job_name)
|
62
|
+
|
63
|
+
client.job.delete job_name
|
64
|
+
|
65
|
+
puts "Done. Job #{job_name} has been deleted"
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_job_config(branch)
|
69
|
+
job_name = job(branch)
|
70
|
+
puts "Fetching configuration of job: #{job_name}"
|
71
|
+
|
72
|
+
fail_on_args_error(branch)
|
73
|
+
fail_on_missing_remote_branch(branch)
|
74
|
+
fail_on_non_existing_job(job_name)
|
75
|
+
|
76
|
+
puts "Done.\n#{client.job.get_config(job_name)}"
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def client
|
82
|
+
@client ||= begin
|
83
|
+
server_url = config['jenkins']['url']
|
84
|
+
proxy_ip = config['jenkins']['proxy_ip']
|
85
|
+
proxy_port = config['jenkins']['proxy_port']
|
86
|
+
|
87
|
+
if proxy_ip.to_s == ''
|
88
|
+
puts "Connecting to Jenkins server #{server_url}"
|
89
|
+
JenkinsApi::Client.new(
|
90
|
+
:server_url => server_url,
|
91
|
+
:username => config['jenkins']['username'],
|
92
|
+
:password => config['jenkins']['password'],
|
93
|
+
:ssl => config['jenkins']['ssl'],
|
94
|
+
:timeout => 300,
|
95
|
+
:log_level => Logger::WARN
|
96
|
+
)
|
97
|
+
else
|
98
|
+
puts "Connecting to Jenkins server #{server_url} via proxy #{proxy_ip}:#{proxy_port}"
|
99
|
+
JenkinsApi::Client.new(
|
100
|
+
:server_url => server_url,
|
101
|
+
:username => config['jenkins']['username'],
|
102
|
+
:password => config['jenkins']['password'],
|
103
|
+
:ssl => config['jenkins']['ssl'],
|
104
|
+
:timeout => 300,
|
105
|
+
:proxy_ip => proxy_ip,
|
106
|
+
:proxy_port => proxy_port,
|
107
|
+
:log_level => Logger::WARN
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def add_email_notification(job_name)
|
115
|
+
user_email_address = config['git']['email']
|
116
|
+
unless user_email_address.empty?
|
117
|
+
client.job.add_email_notification(:name => job_name, :notification_email => user_email_address)
|
118
|
+
puts "Build failures will be emailed to #{user_email_address}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tasks/jenkins_task_configure'
|
3
|
+
|
4
|
+
describe JenkinsTaskConfigure do
|
5
|
+
describe :configure do
|
6
|
+
let(:task) { JenkinsTaskConfigure.new }
|
7
|
+
let(:email) { 'myemail@vodafone.com.au' }
|
8
|
+
let(:jenkins_url) { 'http://myjenkins.com' }
|
9
|
+
let(:jenkins_ssl) { 'true' }
|
10
|
+
let(:proxy_ip) { 'myproxy.com' }
|
11
|
+
let(:proxy_port) { '1234' }
|
12
|
+
let(:jenkins_username) { 'jenkins' }
|
13
|
+
let(:jenkins_password) { 'password' }
|
14
|
+
let(:jenkins_node) { 'jenkins-slave' }
|
15
|
+
let(:jenkins_job_prefix) { 'myproject' }
|
16
|
+
let(:s3_profile) { 'MyS3Profile' }
|
17
|
+
let(:s3_bucket) { 'my-s3-bucket' }
|
18
|
+
let(:s3_region) { 'apac-northwest-12' }
|
19
|
+
let(:file) { mock('file') }
|
20
|
+
|
21
|
+
before {
|
22
|
+
HighLine.stub(:ask).and_return(
|
23
|
+
email,
|
24
|
+
jenkins_url,
|
25
|
+
jenkins_ssl,
|
26
|
+
proxy_ip,
|
27
|
+
proxy_port,
|
28
|
+
jenkins_username,
|
29
|
+
jenkins_password,
|
30
|
+
jenkins_node,
|
31
|
+
jenkins_job_prefix,
|
32
|
+
s3_profile,
|
33
|
+
s3_bucket,
|
34
|
+
s3_region
|
35
|
+
)
|
36
|
+
|
37
|
+
task.stub(:config_file).and_return('my_file.yml')
|
38
|
+
File.stub(:open).and_yield(file)
|
39
|
+
allow(file).to receive(:write)
|
40
|
+
}
|
41
|
+
|
42
|
+
it 'updates the configuration based on user input' do
|
43
|
+
task.configure
|
44
|
+
|
45
|
+
expect(task.config['git']['email']).to eql email
|
46
|
+
expect(task.config['jenkins']['url']).to eql jenkins_url
|
47
|
+
expect(task.config['jenkins']['ssl']).to eql jenkins_ssl
|
48
|
+
expect(task.config['jenkins']['proxy_ip']).to eql proxy_ip
|
49
|
+
expect(task.config['jenkins']['proxy_port']).to eql proxy_port
|
50
|
+
expect(task.config['jenkins']['username']).to eql jenkins_username
|
51
|
+
expect(task.config['jenkins']['password']).to eql jenkins_password
|
52
|
+
expect(task.config['jenkins']['restricted_node']).to eql jenkins_node
|
53
|
+
expect(task.config['jenkins']['job_prefix']).to eql jenkins_job_prefix
|
54
|
+
|
55
|
+
expect(task.config['s3_options']['profile']).to eql s3_profile
|
56
|
+
expect(task.config['s3_options']['bucket']).to eql s3_bucket
|
57
|
+
expect(task.config['s3_options']['region']).to eql s3_region
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'writes the configuration to file' do
|
61
|
+
file.should_receive(:write)
|
62
|
+
|
63
|
+
task.configure
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins-branching
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Chauvet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
executables: []
|
@@ -89,6 +103,7 @@ extra_rdoc_files:
|
|
89
103
|
files:
|
90
104
|
- .document
|
91
105
|
- .gemspec
|
106
|
+
- .rspec
|
92
107
|
- Gemfile
|
93
108
|
- Gemfile.lock
|
94
109
|
- README.md
|
@@ -96,9 +111,13 @@ files:
|
|
96
111
|
- VERSION
|
97
112
|
- jenkins-branching.gemspec
|
98
113
|
- lib/jenkins-branching.rb
|
114
|
+
- lib/tasks/git_task.rb
|
99
115
|
- lib/tasks/jenkins_branching.rake
|
100
|
-
-
|
101
|
-
-
|
116
|
+
- lib/tasks/jenkins_task.rb
|
117
|
+
- lib/tasks/jenkins_task_configure.rb
|
118
|
+
- lib/tasks/jenkins_task_manage_jobs.rb
|
119
|
+
- spec/lib/tasks/jenkins_task_configure_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
102
121
|
homepage:
|
103
122
|
licenses: []
|
104
123
|
metadata: {}
|
data/test/helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
10
|
-
require 'test/unit'
|
11
|
-
require 'shoulda'
|
12
|
-
|
13
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
-
require 'jenkins-branching'
|
16
|
-
|
17
|
-
class Test::Unit::TestCase
|
18
|
-
end
|