jenkins_pipeline_builder 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jenkins_pipeline_builder.gemspec +1 -0
- data/lib/jenkins_pipeline_builder.rb +1 -0
- data/lib/jenkins_pipeline_builder/builders.rb +1 -1
- data/lib/jenkins_pipeline_builder/cli/helper.rb +1 -1
- data/lib/jenkins_pipeline_builder/cli/pipeline.rb +1 -1
- data/lib/jenkins_pipeline_builder/compiler.rb +48 -15
- data/lib/jenkins_pipeline_builder/generator.rb +61 -19
- data/lib/jenkins_pipeline_builder/publishers.rb +18 -3
- data/lib/jenkins_pipeline_builder/version.rb +1 -1
- data/lib/jenkins_pipeline_builder/wrappers.rb +4 -3
- data/spec/unit_tests/compiler_spec.rb +2 -1
- data/spec/unit_tests/fixtures/files/Job-Build-Maven.xml +1 -1
- data/spec/unit_tests/fixtures/files/Job-Gem-Build.yaml +3 -2
- data/spec/unit_tests/fixtures/files/Job-Multi-Project.xml +2 -1
- data/spec/unit_tests/fixtures/files/Job-Multi-Project.yaml +1 -0
- data/spec/unit_tests/fixtures/files/downstream.xml +36 -0
- data/spec/unit_tests/fixtures/files/downstream.yaml +13 -0
- data/spec/unit_tests/fixtures/files/post_build_script.xml +28 -0
- data/spec/unit_tests/fixtures/files/post_build_script.yaml +11 -0
- data/spec/unit_tests/fixtures/files/properties_file.xml +27 -0
- data/spec/unit_tests/fixtures/files/properties_file.yaml +8 -0
- data/spec/unit_tests/generator_spec.rb +15 -6
- data/spec/unit_tests/resolve_dependencies_spec.rb +31 -18
- metadata +28 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ea8f087d4b224af599c56541ff63949b52d753c
|
4
|
+
data.tar.gz: a48aaa32057bb025ff671ecde36ba4a63934d6dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2625db8daaf9376596495cfc9df690833476fd82e9764f703a636b8457782e23fef998bcdc8c64f3e0e8055b34f7ea331384fce2aac6285e3e64c15981b5d9c8
|
7
|
+
data.tar.gz: 34e0e2d66b774240172c5dde403e0fb571ec3b542ca3215af2baa2e081672ef407e0b8cb150040233af0b36c123371a9c98446ebedd49543ec0aeccb60562bb6
|
@@ -24,6 +24,7 @@ automating Job & Pipeline creation from the YAML files checked-in with your appl
|
|
24
24
|
spec.add_dependency 'nokogiri', '~> 1.5.0'
|
25
25
|
spec.add_dependency 'jenkins_api_client', '~> 0.14.1'
|
26
26
|
spec.add_dependency 'thor', '>= 0.18.0'
|
27
|
+
spec.add_dependency 'activesupport'
|
27
28
|
|
28
29
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
29
30
|
spec.add_development_dependency 'rake'
|
@@ -36,7 +36,7 @@ module JenkinsPipelineBuilder
|
|
36
36
|
xml.configs {
|
37
37
|
if job[:config].has_key? :predefined_build_parameters
|
38
38
|
xml.send('hudson.plugins.parameterizedtrigger.PredefinedBuildParameters') {
|
39
|
-
xml.properties job[:config][:predefined_build_parameters].join
|
39
|
+
xml.properties job[:config][:predefined_build_parameters].join "\n"
|
40
40
|
}
|
41
41
|
end
|
42
42
|
}
|
@@ -23,10 +23,11 @@
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
24
|
class Compiler
|
25
25
|
def self.resolve_value(value, settings)
|
26
|
+
settings = settings.with_indifferent_access
|
26
27
|
value_s = value.to_s.clone
|
27
|
-
vars = value_s.scan(/{{([^}]+)}}/).flatten
|
28
|
+
vars = value_s.scan(/{{([^{}]+)}}/).flatten
|
28
29
|
vars.select! do |var|
|
29
|
-
var_val = settings[var
|
30
|
+
var_val = settings[var]
|
30
31
|
value_s.gsub!("{{#{var.to_s}}}", var_val) unless var_val.nil?
|
31
32
|
var_val.nil?
|
32
33
|
end
|
@@ -51,31 +52,63 @@ module JenkinsPipelineBuilder
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def self.compile(item, settings = {})
|
55
|
+
errors = {}
|
54
56
|
case item
|
55
57
|
when String
|
56
58
|
new_value = resolve_value(item, settings)
|
57
|
-
|
58
|
-
|
59
|
+
if new_value.nil?
|
60
|
+
errors[item] = "Failed to resolve #{item}"
|
61
|
+
end
|
62
|
+
unless errors.empty?
|
63
|
+
return false, errors
|
64
|
+
end
|
65
|
+
return true, new_value
|
59
66
|
when Hash
|
60
67
|
result = {}
|
61
68
|
item.each do |key, value|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
69
|
+
if value.nil?
|
70
|
+
errors[key] = "key: #{key} has a nil value, this is likely a yaml syntax error. Skipping children and siblings"
|
71
|
+
break
|
72
|
+
end
|
73
|
+
success, payload = compile(value, settings)
|
74
|
+
unless success
|
75
|
+
errors.merge!(payload)
|
76
|
+
next
|
77
|
+
end
|
78
|
+
if payload.nil?
|
79
|
+
errors[key] = "Failed to resolve:\n===>key: #{key}\n\n===>value: #{value}\n\n===>of: #{item}"
|
80
|
+
next
|
81
|
+
end
|
82
|
+
result[key] = payload
|
66
83
|
end
|
67
|
-
|
84
|
+
unless errors.empty?
|
85
|
+
return false, errors
|
86
|
+
end
|
87
|
+
return true, result
|
68
88
|
when Array
|
69
89
|
result = []
|
70
90
|
item.each do |value|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
91
|
+
if value.nil?
|
92
|
+
errors[item] = "found a nil value when processing following array:\n #{item.inspect}"
|
93
|
+
break
|
94
|
+
end
|
95
|
+
success, payload = compile(value, settings)
|
96
|
+
unless success
|
97
|
+
errors.merge!(payload)
|
98
|
+
next
|
99
|
+
end
|
100
|
+
if payload.nil?
|
101
|
+
errors[value] = "Failed to resolve:\n===>item #{value}\n\n===>of list: #{item}"
|
102
|
+
next
|
103
|
+
end
|
104
|
+
result << payload
|
105
|
+
end
|
106
|
+
unless errors.empty?
|
107
|
+
return false, errors
|
75
108
|
end
|
76
|
-
return result
|
109
|
+
return true, result
|
77
110
|
end
|
78
|
-
return item
|
111
|
+
return true, item
|
79
112
|
end
|
80
113
|
end
|
81
114
|
end
|
@@ -65,7 +65,8 @@ module JenkinsPipelineBuilder
|
|
65
65
|
description_setter: Publishers.method(:description_setter),
|
66
66
|
downstream: Publishers.method(:push_to_projects),
|
67
67
|
junit_result: Publishers.method(:publish_junit),
|
68
|
-
coverage_result: Publishers.method(:publish_rcov)
|
68
|
+
coverage_result: Publishers.method(:publish_rcov),
|
69
|
+
post_build_script: Publishers.method(:post_build_script)
|
69
70
|
},
|
70
71
|
method:
|
71
72
|
lambda { |registry, params, n_xml| @module_registry.run_registry_on_path('//publishers', registry, params, n_xml) }
|
@@ -96,7 +97,6 @@ module JenkinsPipelineBuilder
|
|
96
97
|
end
|
97
98
|
|
98
99
|
attr_accessor :client
|
99
|
-
#attr_accessor :debug
|
100
100
|
def debug=(value)
|
101
101
|
@debug = value
|
102
102
|
@logger.level = (value) ? Logger::DEBUG : Logger::INFO;
|
@@ -166,11 +166,17 @@ module JenkinsPipelineBuilder
|
|
166
166
|
jobs.map! do |job|
|
167
167
|
job.kind_of?(String) ? { job.to_sym => {} } : job
|
168
168
|
end
|
169
|
+
errors = {}
|
169
170
|
@logger.info project
|
170
171
|
jobs.each do |job|
|
171
172
|
job_id = job.keys.first
|
172
173
|
settings = project[:settings].clone.merge(job[job_id])
|
173
|
-
|
174
|
+
success, payload = resolve_job_by_name(job_id, settings)
|
175
|
+
if success
|
176
|
+
job[:result] = payload
|
177
|
+
else
|
178
|
+
errors[job_id] = payload
|
179
|
+
end
|
174
180
|
end
|
175
181
|
|
176
182
|
# Process views
|
@@ -182,10 +188,24 @@ module JenkinsPipelineBuilder
|
|
182
188
|
view_id = view.keys.first
|
183
189
|
settings = project[:settings].clone.merge(view[view_id])
|
184
190
|
# TODO: rename resolve_job_by_name properly
|
185
|
-
|
191
|
+
success, payload = resolve_job_by_name(view_id, settings)
|
192
|
+
if success
|
193
|
+
view[:result] = payload
|
194
|
+
else
|
195
|
+
errors[view_id] = payload
|
196
|
+
end
|
186
197
|
end
|
187
198
|
|
188
|
-
|
199
|
+
errors.each do |k,v|
|
200
|
+
puts "Encountered errors processing: #{k}:"
|
201
|
+
v.each do |key, error|
|
202
|
+
puts " key: #{key} had the following error:"
|
203
|
+
puts " #{error.inspect}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
return false, "Encountered errors exiting" unless errors.empty?
|
207
|
+
|
208
|
+
return true, project
|
189
209
|
end
|
190
210
|
|
191
211
|
def resolve_job_by_name(name, settings = {})
|
@@ -193,8 +213,9 @@ module JenkinsPipelineBuilder
|
|
193
213
|
raise "Failed to locate job by name '#{name}'" if job.nil?
|
194
214
|
job_value = job[:value]
|
195
215
|
@logger.debug "Compiling job #{name}"
|
196
|
-
|
197
|
-
|
216
|
+
|
217
|
+
success, payload = Compiler.compile(job_value, settings)
|
218
|
+
return success, payload
|
198
219
|
end
|
199
220
|
|
200
221
|
def projects
|
@@ -217,23 +238,40 @@ module JenkinsPipelineBuilder
|
|
217
238
|
@logger.info "Bootstrapping pipeline from path #{path}"
|
218
239
|
load_collection_from_path(path)
|
219
240
|
|
241
|
+
errors = {}
|
220
242
|
# Publish all the jobs if the projects are not found
|
221
243
|
if projects.count == 0
|
222
244
|
jobs.each do |i|
|
223
245
|
job = i[:value]
|
224
|
-
|
225
|
-
|
246
|
+
success, payload = compile_job_to_xml(job)
|
247
|
+
if success
|
248
|
+
create_or_update(job, payload)
|
249
|
+
else
|
250
|
+
errors[job[:name]] = payload
|
251
|
+
end
|
226
252
|
end
|
227
253
|
else
|
228
254
|
projects.each do |project|
|
229
|
-
|
230
|
-
|
255
|
+
success, payload = resolve_project(project)
|
256
|
+
if success
|
257
|
+
puts 'successfully resolved project'
|
258
|
+
compiled_project = payload
|
259
|
+
else
|
260
|
+
puts payload
|
261
|
+
return false
|
262
|
+
end
|
231
263
|
|
232
264
|
if compiled_project[:value][:jobs]
|
233
265
|
compiled_project[:value][:jobs].each do |i|
|
266
|
+
puts "Processing #{i}"
|
234
267
|
job = i[:result]
|
235
|
-
|
236
|
-
|
268
|
+
fail "Result is empty for #{i}" if job.nil?
|
269
|
+
success, payload = compile_job_to_xml(job)
|
270
|
+
if success
|
271
|
+
create_or_update(job, payload)
|
272
|
+
else
|
273
|
+
errors[job[:name]] = payload
|
274
|
+
end
|
237
275
|
end
|
238
276
|
end
|
239
277
|
|
@@ -245,6 +283,10 @@ module JenkinsPipelineBuilder
|
|
245
283
|
end
|
246
284
|
end
|
247
285
|
end
|
286
|
+
errors.each do |k,v|
|
287
|
+
@logger.error "Encountered errors compiling: #{k}:"
|
288
|
+
@logger.error v
|
289
|
+
end
|
248
290
|
end
|
249
291
|
|
250
292
|
def dump(job_name)
|
@@ -278,20 +320,20 @@ module JenkinsPipelineBuilder
|
|
278
320
|
case job[:job_type]
|
279
321
|
when 'job_dsl'
|
280
322
|
xml = compile_freestyle_job_to_xml(job)
|
281
|
-
update_job_dsl(job, xml)
|
323
|
+
payload = update_job_dsl(job, xml)
|
282
324
|
when 'multi_project'
|
283
325
|
xml = compile_freestyle_job_to_xml(job)
|
284
|
-
adjust_multi_project xml
|
326
|
+
payload = adjust_multi_project xml
|
285
327
|
when 'build_flow'
|
286
328
|
xml = compile_freestyle_job_to_xml(job)
|
287
|
-
add_job_dsl(job, xml)
|
329
|
+
payload = add_job_dsl(job, xml)
|
288
330
|
when 'free_style'
|
289
|
-
compile_freestyle_job_to_xml job
|
331
|
+
payload = compile_freestyle_job_to_xml job
|
290
332
|
else
|
291
|
-
|
292
|
-
''
|
333
|
+
return false, "Job type: #{job[:job_type]} is not one of job_dsl, multi_project, build_flow or free_style"
|
293
334
|
end
|
294
335
|
|
336
|
+
return true, payload
|
295
337
|
end
|
296
338
|
|
297
339
|
def adjust_multi_project(xml)
|
@@ -53,8 +53,8 @@ module JenkinsPipelineBuilder
|
|
53
53
|
end
|
54
54
|
}
|
55
55
|
xml.projects params[:project]
|
56
|
-
xml.condition 'SUCCESS'
|
57
|
-
xml.triggerWithNoParameters false
|
56
|
+
xml.condition params[:condition] || 'SUCCESS'
|
57
|
+
xml.triggerWithNoParameters params[:trigger_with_no_parameters] || false
|
58
58
|
}
|
59
59
|
}
|
60
60
|
}
|
@@ -109,5 +109,20 @@ module JenkinsPipelineBuilder
|
|
109
109
|
}
|
110
110
|
}
|
111
111
|
end
|
112
|
+
|
113
|
+
def self.post_build_script(params, xml)
|
114
|
+
xml.send('org.jenkinsci.plugins.postbuildscript.PostBuildScript') {
|
115
|
+
xml.buildSteps {
|
116
|
+
if params[:shell_command]
|
117
|
+
xml.send('hudson.tasks.Shell') {
|
118
|
+
xml.command params[:shell_command]
|
119
|
+
}
|
120
|
+
end
|
121
|
+
}
|
122
|
+
xml.scriptOnlyIfSuccess params[:on_success]
|
123
|
+
xml.scriptOnlyIfFailure params[:on_failure]
|
124
|
+
xml.executeOn params[:execute_on] || 'BOTH'
|
125
|
+
}
|
126
|
+
end
|
112
127
|
end
|
113
|
-
end
|
128
|
+
end
|
@@ -57,10 +57,11 @@ module JenkinsPipelineBuilder
|
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
60
|
-
def self.inject_env_vars(
|
60
|
+
def self.inject_env_vars(params, xml)
|
61
61
|
xml.EnvInjectBuildWrapper {
|
62
62
|
xml.info {
|
63
|
-
xml.
|
63
|
+
xml.propertiesFilePath params[:file] if params[:file]
|
64
|
+
xml.propertiesContent params[:content] if params[:content]
|
64
65
|
xml.loadFilesFromMaster false
|
65
66
|
}
|
66
67
|
}
|
@@ -130,4 +131,4 @@ module JenkinsPipelineBuilder
|
|
130
131
|
}
|
131
132
|
end
|
132
133
|
end
|
133
|
-
end
|
134
|
+
end
|
@@ -76,7 +76,8 @@
|
|
76
76
|
<exposedSCM>true</exposedSCM>
|
77
77
|
<configs>
|
78
78
|
<hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
79
|
-
<properties>
|
79
|
+
<properties>GIT_COMMIT=123
|
80
|
+
PARENT_WORKSPACE=${WORKSPACE}</properties>
|
80
81
|
</hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
81
82
|
</configs>
|
82
83
|
</com.tikal.jenkins.plugins.multijob.PhaseJobsConfig>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project>
|
3
|
+
<actions/>
|
4
|
+
<description/>
|
5
|
+
<keepDependencies>false</keepDependencies>
|
6
|
+
<properties/>
|
7
|
+
<scm class="hudson.scm.NullSCM"/>
|
8
|
+
<canRoam>true</canRoam>
|
9
|
+
<disabled>false</disabled>
|
10
|
+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
11
|
+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
12
|
+
<triggers class="vector"/>
|
13
|
+
<concurrentBuild>false</concurrentBuild>
|
14
|
+
<builders/>
|
15
|
+
<publishers>
|
16
|
+
<hudson.plugins.parameterizedtrigger.BuildTrigger>
|
17
|
+
<configs>
|
18
|
+
<hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
|
19
|
+
<configs>
|
20
|
+
<hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
21
|
+
<properties>param1 param2</properties>
|
22
|
+
</hudson.plugins.parameterizedtrigger.PredefinedBuildParameters>
|
23
|
+
<hudson.plugins.parameterizedtrigger.FileBuildParameters>
|
24
|
+
<propertiesFile>props.file</propertiesFile>
|
25
|
+
<failTriggerOnMissing>false</failTriggerOnMissing>
|
26
|
+
</hudson.plugins.parameterizedtrigger.FileBuildParameters>
|
27
|
+
</configs>
|
28
|
+
<projects>downstream</projects>
|
29
|
+
<condition>FAILURE</condition>
|
30
|
+
<triggerWithNoParameters>false</triggerWithNoParameters>
|
31
|
+
</hudson.plugins.parameterizedtrigger.BuildTriggerConfig>
|
32
|
+
</configs>
|
33
|
+
</hudson.plugins.parameterizedtrigger.BuildTrigger>
|
34
|
+
</publishers>
|
35
|
+
<buildWrappers/>
|
36
|
+
</project>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project>
|
3
|
+
<actions/>
|
4
|
+
<description/>
|
5
|
+
<keepDependencies>false</keepDependencies>
|
6
|
+
<properties/>
|
7
|
+
<scm class="hudson.scm.NullSCM"/>
|
8
|
+
<canRoam>true</canRoam>
|
9
|
+
<disabled>false</disabled>
|
10
|
+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
11
|
+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
12
|
+
<triggers class="vector"/>
|
13
|
+
<concurrentBuild>false</concurrentBuild>
|
14
|
+
<builders/>
|
15
|
+
<publishers>
|
16
|
+
<org.jenkinsci.plugins.postbuildscript.PostBuildScript>
|
17
|
+
<buildSteps>
|
18
|
+
<hudson.tasks.Shell>
|
19
|
+
<command>echo "line one" echo "line two"</command>
|
20
|
+
</hudson.tasks.Shell>
|
21
|
+
</buildSteps>
|
22
|
+
<scriptOnlyIfSuccess>true</scriptOnlyIfSuccess>
|
23
|
+
<scriptOnlyIfFailure>false</scriptOnlyIfFailure>
|
24
|
+
<executeOn>BOTH</executeOn>
|
25
|
+
</org.jenkinsci.plugins.postbuildscript.PostBuildScript>
|
26
|
+
</publishers>
|
27
|
+
<buildWrappers/>
|
28
|
+
</project>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project>
|
3
|
+
<actions/>
|
4
|
+
<description/>
|
5
|
+
<keepDependencies>false</keepDependencies>
|
6
|
+
<properties/>
|
7
|
+
<scm class="hudson.scm.NullSCM"/>
|
8
|
+
<canRoam>true</canRoam>
|
9
|
+
<disabled>false</disabled>
|
10
|
+
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
11
|
+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
12
|
+
<triggers class="vector"/>
|
13
|
+
<concurrentBuild>false</concurrentBuild>
|
14
|
+
<builders/>
|
15
|
+
<publishers/>
|
16
|
+
<buildWrappers>
|
17
|
+
<EnvInjectBuildWrapper>
|
18
|
+
<info>
|
19
|
+
<propertiesFilePath>foo.prop</propertiesFilePath>
|
20
|
+
<propertiesContent>
|
21
|
+
foo=bar
|
22
|
+
</propertiesContent>
|
23
|
+
<loadFilesFromMaster>false</loadFilesFromMaster>
|
24
|
+
</info>
|
25
|
+
</EnvInjectBuildWrapper>
|
26
|
+
</buildWrappers>
|
27
|
+
</project>
|
@@ -16,7 +16,8 @@ describe 'Test YAML jobs conversion to XML' do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def compare_jobs(job, path)
|
19
|
-
xml = @generator.compile_job_to_xml(job)
|
19
|
+
success, xml = @generator.compile_job_to_xml(job)
|
20
|
+
expect(success).to be_true
|
20
21
|
doc1 = Nokogiri::XML(xml)
|
21
22
|
|
22
23
|
sample_job_xml = File.read(path + '.xml')
|
@@ -26,19 +27,25 @@ describe 'Test YAML jobs conversion to XML' do
|
|
26
27
|
doc1.should be_equivalent_to(doc2)
|
27
28
|
end
|
28
29
|
|
29
|
-
[
|
30
|
+
files = [
|
30
31
|
'Job-Multi-Project',
|
31
32
|
'Job-Build-Maven',
|
32
33
|
'Job-Build-Flow',
|
33
|
-
'Job-Gem-Build'
|
34
|
-
|
34
|
+
'Job-Gem-Build',
|
35
|
+
'post_build_script',
|
36
|
+
'properties_file',
|
37
|
+
'downstream'
|
38
|
+
]
|
39
|
+
|
40
|
+
files.each do |file|
|
35
41
|
it "should create expected XML from YAML '#{file}'" do
|
36
42
|
path = File.expand_path('../fixtures/files/' + file, __FILE__)
|
37
43
|
|
38
44
|
@generator.load_collection_from_path path + '.yaml'
|
39
45
|
job_name = @generator.job_collection.keys.first
|
40
|
-
job = @generator.resolve_job_by_name(job_name)
|
46
|
+
success, job = @generator.resolve_job_by_name(job_name)
|
41
47
|
|
48
|
+
expect(success).to be_true
|
42
49
|
compare_jobs job, path
|
43
50
|
end
|
44
51
|
end
|
@@ -50,7 +57,9 @@ describe 'Test YAML jobs conversion to XML' do
|
|
50
57
|
|
51
58
|
project_name = @generator.projects.first[:name]
|
52
59
|
|
53
|
-
project = @generator.resolve_project(@generator.get_item(project_name))
|
60
|
+
success, project = @generator.resolve_project(@generator.get_item(project_name))
|
61
|
+
|
62
|
+
expect(success).to be_true
|
54
63
|
|
55
64
|
project[:value][:jobs].should_not be_nil
|
56
65
|
|
@@ -63,8 +63,10 @@ describe 'Templates resolver' do
|
|
63
63
|
project = YAML.load(str)
|
64
64
|
@generator.load_job_collection project
|
65
65
|
|
66
|
-
@generator.resolve_project(@generator.get_item('project-name'))
|
67
|
-
|
66
|
+
success, project = @generator.resolve_project(@generator.get_item('project-name'))
|
67
|
+
|
68
|
+
expect(success).to be_true
|
69
|
+
expect(project).to eq({:name=>"project-name",
|
68
70
|
:type=>:project,
|
69
71
|
:value=>
|
70
72
|
{:name=>"project-name",
|
@@ -78,7 +80,7 @@ describe 'Templates resolver' do
|
|
78
80
|
:settings=>
|
79
81
|
{:name=>"project-name",
|
80
82
|
:description=>"Do not edit this job through the web!",
|
81
|
-
:db=>"my_own_db"}}
|
83
|
+
:db=>"my_own_db"}})
|
82
84
|
end
|
83
85
|
|
84
86
|
it 'should build project collection from jobs templates' do
|
@@ -112,8 +114,9 @@ describe 'Templates resolver' do
|
|
112
114
|
project = YAML.load(str)
|
113
115
|
@generator.load_job_collection project
|
114
116
|
|
115
|
-
@generator.resolve_project(@generator.get_item('project-name'))
|
116
|
-
|
117
|
+
success, project = @generator.resolve_project(@generator.get_item('project-name'))
|
118
|
+
expect(success).to be_true
|
119
|
+
expect(project).to eq( {:name=>"project-name",
|
117
120
|
:type=>:project,
|
118
121
|
:value=>
|
119
122
|
{:name=>"project-name",
|
@@ -129,7 +132,7 @@ describe 'Templates resolver' do
|
|
129
132
|
{:name=>"project-name-perf-tests",
|
130
133
|
:builders=>[{:shell=>"perftest"}],
|
131
134
|
:publishers=>[{:email=>{:recipients=>"projmanager@nowhere.net"}}]}}]},
|
132
|
-
:settings=>{:name=>"project-name", :db=>"my_own_db"}}
|
135
|
+
:settings=>{:name=>"project-name", :db=>"my_own_db"}})
|
133
136
|
end
|
134
137
|
|
135
138
|
it 'should build project collection from jobs and jobs templates' do
|
@@ -159,7 +162,9 @@ describe 'Templates resolver' do
|
|
159
162
|
project = YAML.load(str)
|
160
163
|
@generator.load_job_collection project
|
161
164
|
|
162
|
-
@generator.resolve_project(@generator.get_item('project-name'))
|
165
|
+
success, project = @generator.resolve_project(@generator.get_item('project-name'))
|
166
|
+
expect(success).to be_true
|
167
|
+
expect(project).to eq(
|
163
168
|
{:name=>"project-name",
|
164
169
|
:type=>:project,
|
165
170
|
:value=>
|
@@ -175,23 +180,27 @@ describe 'Templates resolver' do
|
|
175
180
|
{:name=>"project-name-unit-tests",
|
176
181
|
:builders=>[{:shell=>"unittest"}],
|
177
182
|
:publishers=>[{:email=>{:recipients=>"projmanager@nowhere.net"}}]}}]},
|
178
|
-
:settings=>{:name=>"project-name", :db=>"my_own_db"}}
|
183
|
+
:settings=>{:name=>"project-name", :db=>"my_own_db"}})
|
179
184
|
end
|
180
185
|
|
181
186
|
|
182
187
|
describe 'compilation of templates' do
|
183
188
|
it 'compiles String' do
|
184
|
-
JenkinsPipelineBuilder::Compiler.compile('blah', { item1: 'data1'})
|
189
|
+
success, string = JenkinsPipelineBuilder::Compiler.compile('blah', { item1: 'data1'})
|
190
|
+
expect(success).to be_true
|
191
|
+
expect(string).to eq 'blah'
|
185
192
|
end
|
186
193
|
|
187
194
|
it 'compiles simple Hash' do
|
188
|
-
JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: 'item1-data'}, { item1: 'data1'})
|
189
|
-
|
195
|
+
success, hash = JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: 'item1-data'}, { item1: 'data1'})
|
196
|
+
expect(success).to be_true
|
197
|
+
expect(hash).to eq({ name: 'item-data1', value: 'item1-data'})
|
190
198
|
end
|
191
199
|
|
192
200
|
it 'compiles nested Hash' do
|
193
|
-
JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: { house: 'house-{{item1}}'}}, { item1: 'data1'})
|
194
|
-
|
201
|
+
success, hash = JenkinsPipelineBuilder::Compiler.compile({ name: 'item-{{item1}}', value: { house: 'house-{{item1}}'}}, { item1: 'data1'})
|
202
|
+
expect(success).to be_true
|
203
|
+
expect(hash).to eq( { name: 'item-data1', value: { house: 'house-data1'}} )
|
195
204
|
end
|
196
205
|
|
197
206
|
it 'compiles complex Hash' do
|
@@ -200,10 +209,12 @@ describe 'Templates resolver' do
|
|
200
209
|
:publishers=>[{:email=>{:recipients=>"{{mail-to}}"}}]}
|
201
210
|
settings = {:name=>"project-name", :db=>"my_own_db", :'mail-to' => 'developer@nowhere.net'}
|
202
211
|
|
203
|
-
JenkinsPipelineBuilder::Compiler.compile(template, settings)
|
212
|
+
success, hash = JenkinsPipelineBuilder::Compiler.compile(template, settings)
|
213
|
+
expect(success).to be_true
|
214
|
+
expect(hash).to eq(
|
204
215
|
{:name=>"project-name-unit-tests",
|
205
216
|
:builders=>[{:shell=>"unittest"}],
|
206
|
-
:publishers=>[{:email=>{:recipients=>"developer@nowhere.net"}}]}
|
217
|
+
:publishers=>[{:email=>{:recipients=>"developer@nowhere.net"}}]})
|
207
218
|
end
|
208
219
|
end
|
209
220
|
|
@@ -214,10 +225,12 @@ describe 'Templates resolver' do
|
|
214
225
|
|
215
226
|
@generator.load_job_collection project
|
216
227
|
|
217
|
-
@generator.resolve_job_by_name('{{name}}-unit-tests', { name: 'project-name', db: 'my_own_db', :'mail-to' => 'developer@nowhere.net' })
|
228
|
+
success, job = @generator.resolve_job_by_name('{{name}}-unit-tests', { name: 'project-name', db: 'my_own_db', :'mail-to' => 'developer@nowhere.net' })
|
229
|
+
expect(success).to be_true
|
230
|
+
expect(job).to eq(
|
218
231
|
{:name=>"project-name-unit-tests",
|
219
232
|
:builders=>[{:shell=>"unittest"}],
|
220
|
-
:publishers=>[{:email=>{:recipients=>"developer@nowhere.net"}}]}
|
233
|
+
:publishers=>[{:email=>{:recipients=>"developer@nowhere.net"}}]})
|
221
234
|
end
|
222
235
|
|
223
236
|
it 'should load from folder' do
|
@@ -227,4 +240,4 @@ describe 'Templates resolver' do
|
|
227
240
|
@generator.job_collection.count.should == 4
|
228
241
|
@generator.projects.count == 1
|
229
242
|
end
|
230
|
-
end
|
243
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins_pipeline_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Moochnick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.18.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -305,7 +319,13 @@ files:
|
|
305
319
|
- spec/unit_tests/fixtures/files/Job-Generate-From-Template.yaml
|
306
320
|
- spec/unit_tests/fixtures/files/Job-Multi-Project.xml
|
307
321
|
- spec/unit_tests/fixtures/files/Job-Multi-Project.yaml
|
322
|
+
- spec/unit_tests/fixtures/files/downstream.xml
|
323
|
+
- spec/unit_tests/fixtures/files/downstream.yaml
|
324
|
+
- spec/unit_tests/fixtures/files/post_build_script.xml
|
325
|
+
- spec/unit_tests/fixtures/files/post_build_script.yaml
|
308
326
|
- spec/unit_tests/fixtures/files/project.yaml
|
327
|
+
- spec/unit_tests/fixtures/files/properties_file.xml
|
328
|
+
- spec/unit_tests/fixtures/files/properties_file.yaml
|
309
329
|
- spec/unit_tests/fixtures/templates/external_job.yaml
|
310
330
|
- spec/unit_tests/fixtures/templates/project_with_jobs.yaml
|
311
331
|
- spec/unit_tests/generator_spec.rb
|
@@ -353,7 +373,13 @@ test_files:
|
|
353
373
|
- spec/unit_tests/fixtures/files/Job-Generate-From-Template.yaml
|
354
374
|
- spec/unit_tests/fixtures/files/Job-Multi-Project.xml
|
355
375
|
- spec/unit_tests/fixtures/files/Job-Multi-Project.yaml
|
376
|
+
- spec/unit_tests/fixtures/files/downstream.xml
|
377
|
+
- spec/unit_tests/fixtures/files/downstream.yaml
|
378
|
+
- spec/unit_tests/fixtures/files/post_build_script.xml
|
379
|
+
- spec/unit_tests/fixtures/files/post_build_script.yaml
|
356
380
|
- spec/unit_tests/fixtures/files/project.yaml
|
381
|
+
- spec/unit_tests/fixtures/files/properties_file.xml
|
382
|
+
- spec/unit_tests/fixtures/files/properties_file.yaml
|
357
383
|
- spec/unit_tests/fixtures/templates/external_job.yaml
|
358
384
|
- spec/unit_tests/fixtures/templates/project_with_jobs.yaml
|
359
385
|
- spec/unit_tests/generator_spec.rb
|