jenkins_pipeline_builder 0.10.12 → 0.10.13
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.
- checksums.yaml +8 -8
- data/.rubocop.yml +2 -2
- data/README.md +6 -12
- data/lib/jenkins_pipeline_builder/compiler.rb +82 -67
- data/lib/jenkins_pipeline_builder/extension_set.rb +4 -0
- data/lib/jenkins_pipeline_builder/extensions.rb +26 -0
- data/lib/jenkins_pipeline_builder/extensions/builders.rb +6 -0
- data/lib/jenkins_pipeline_builder/generator.rb +39 -124
- data/lib/jenkins_pipeline_builder/job.rb +1 -0
- data/lib/jenkins_pipeline_builder/job_collection.rb +17 -15
- data/lib/jenkins_pipeline_builder/module_registry.rb +1 -26
- data/lib/jenkins_pipeline_builder/pull_request.rb +6 -10
- data/lib/jenkins_pipeline_builder/pull_request_generator.rb +93 -13
- data/lib/jenkins_pipeline_builder/version.rb +1 -1
- data/lib/jenkins_pipeline_builder/view.rb +10 -20
- data/spec/lib/jenkins_pipeline_builder/compiler_spec.rb +78 -21
- data/spec/lib/jenkins_pipeline_builder/extensions/builders_spec.rb +10 -1
- data/spec/lib/jenkins_pipeline_builder/generator_spec.rb +26 -72
- data/spec/lib/jenkins_pipeline_builder/job_spec.rb +142 -0
- data/spec/lib/jenkins_pipeline_builder/module_registry_spec.rb +2 -0
- data/spec/lib/jenkins_pipeline_builder/pull_request_generator_spec.rb +8 -4
- data/spec/lib/jenkins_pipeline_builder/pull_request_spec.rb +10 -4
- data/spec/lib/jenkins_pipeline_builder/view_spec.rb +1 -0
- metadata +4 -3
@@ -44,6 +44,7 @@ module JenkinsPipelineBuilder
|
|
44
44
|
@xml = setup_freestyle_base(job)
|
45
45
|
payload = update_job_dsl
|
46
46
|
when 'multi_project'
|
47
|
+
# TODO: Add multi_job as another, more logically named option
|
47
48
|
@xml = setup_freestyle_base(job)
|
48
49
|
payload = adjust_multi_project
|
49
50
|
when 'build_flow'
|
@@ -23,6 +23,10 @@ module JenkinsPipelineBuilder
|
|
23
23
|
result
|
24
24
|
end
|
25
25
|
|
26
|
+
def standalone_jobs
|
27
|
+
jobs.map { |job| { result: job } }
|
28
|
+
end
|
29
|
+
|
26
30
|
def jobs
|
27
31
|
result = []
|
28
32
|
collection.values.each do |item|
|
@@ -49,29 +53,27 @@ module JenkinsPipelineBuilder
|
|
49
53
|
if File.directory?(path)
|
50
54
|
logger.info "Generating from folder #{path}"
|
51
55
|
Dir[File.join(path, '/*.{yaml,yml}')].each do |file|
|
52
|
-
|
53
|
-
yaml = YAML.load_file(file)
|
54
|
-
load_file(yaml, remote)
|
56
|
+
load_file(file, remote)
|
55
57
|
end
|
56
58
|
Dir[File.join(path, '/*.json')].each do |file|
|
57
|
-
|
58
|
-
json = JSON.parse(IO.read(file))
|
59
|
-
load_file(json, remote)
|
59
|
+
load_file(file, remote)
|
60
60
|
end
|
61
61
|
else
|
62
|
-
|
63
|
-
if path.end_with? 'json'
|
64
|
-
hash = JSON.parse(IO.read(path))
|
65
|
-
else # elsif path.end_with?("yml") || path.end_with?("yaml")
|
66
|
-
hash = YAML.load_file(path)
|
67
|
-
end
|
68
|
-
load_file(hash, remote)
|
62
|
+
load_file(path, remote)
|
69
63
|
end
|
70
64
|
remote_dependencies.cleanup if remote
|
71
65
|
end
|
72
66
|
|
73
|
-
|
74
|
-
|
67
|
+
private
|
68
|
+
|
69
|
+
def load_file(path, remote = false)
|
70
|
+
if path.end_with? 'json'
|
71
|
+
hash = JSON.parse(IO.read(path))
|
72
|
+
else # elsif path.end_with?("yml") || path.end_with?("yaml")
|
73
|
+
hash = YAML.load_file(path)
|
74
|
+
end
|
75
|
+
logger.info "Loading file #{path}"
|
76
|
+
hash.each do |section|
|
75
77
|
Utils.symbolize_keys_deep!(section)
|
76
78
|
key = section.keys.first
|
77
79
|
value = section[key]
|
@@ -93,7 +93,7 @@ module JenkinsPipelineBuilder
|
|
93
93
|
if reg_value.is_a? ExtensionSet
|
94
94
|
ext = reg_value.extension
|
95
95
|
logger.debug "Using #{ext.type} #{ext.name} version #{ext.min_version}"
|
96
|
-
success =
|
96
|
+
success = ext.execute value, n_xml
|
97
97
|
fail 'Encountered errors compiling the xml' unless success
|
98
98
|
elsif value.is_a? Hash
|
99
99
|
traverse_registry reg_value, value, n_xml, true
|
@@ -104,30 +104,5 @@ module JenkinsPipelineBuilder
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
107
|
-
|
108
|
-
def execute_extension(extension, value, n_xml)
|
109
|
-
errors = []
|
110
|
-
params = extension.parameters
|
111
|
-
if params == false || params.any?
|
112
|
-
if value.is_a? Hash
|
113
|
-
value.each_key do |key|
|
114
|
-
next if params && params.include?(key)
|
115
|
-
errors << "Extension #{extension.name} does not support parameter #{key}"
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
errors.each do |error|
|
120
|
-
logger.error error
|
121
|
-
end
|
122
|
-
return false if errors.any?
|
123
|
-
|
124
|
-
n_builders = n_xml.xpath(extension.path).first
|
125
|
-
n_builders.instance_exec(value, &extension.before) if extension.before
|
126
|
-
Nokogiri::XML::Builder.with(n_builders) do |xml|
|
127
|
-
xml.instance_exec value, &extension.xml
|
128
|
-
end
|
129
|
-
n_builders.instance_exec(value, &extension.after) if extension.after
|
130
|
-
true
|
131
|
-
end
|
132
107
|
end
|
133
108
|
end
|
@@ -24,24 +24,20 @@ module JenkinsPipelineBuilder
|
|
24
24
|
attr_reader :project # The root project YAML as a hash
|
25
25
|
attr_reader :number # The pull request number
|
26
26
|
attr_reader :jobs # The jobs in the pull request as an array of hashes
|
27
|
-
attr_reader :
|
27
|
+
attr_reader :pull_generator # The generator job YAML as a hash
|
28
28
|
|
29
|
-
|
30
|
-
def initialize(project, number, jobs, generator)
|
31
|
-
# Set instance vars
|
29
|
+
def initialize(project, number, jobs, pull_generator)
|
32
30
|
@project = Marshal.load(Marshal.dump(project))
|
33
31
|
@number = number
|
34
32
|
@jobs = Marshal.load(Marshal.dump(jobs))
|
35
|
-
@
|
33
|
+
@pull_generator = Marshal.load(Marshal.dump(pull_generator))
|
36
34
|
@project[:value][:pull_request_number] = "#{@number}"
|
37
35
|
|
38
|
-
# Run
|
39
36
|
run!
|
40
37
|
end
|
41
38
|
|
42
39
|
private
|
43
40
|
|
44
|
-
# Apply all changes
|
45
41
|
def run!
|
46
42
|
git_version = JenkinsPipelineBuilder.registry.registry[:job][:scm_params].installed_version
|
47
43
|
if git_version >= Gem::Version.new(2.0)
|
@@ -64,7 +60,8 @@ module JenkinsPipelineBuilder
|
|
64
60
|
@jobs.each_value do |job|
|
65
61
|
job[:value][:scm_branch] = 'origin/pr/{{pull_request_number}}/head'
|
66
62
|
job[:value][:scm_params] = {} unless job[:value][:scm_params]
|
67
|
-
|
63
|
+
refspec = 'refs/pull/{{pull_request_number}}/head:refs/remotes/origin/pr/{{pull_request_number}}/head'
|
64
|
+
job[:value][:scm_params][:refspec] = refspec
|
68
65
|
end
|
69
66
|
end
|
70
67
|
|
@@ -79,8 +76,7 @@ module JenkinsPipelineBuilder
|
|
79
76
|
@jobs.each_value do |job|
|
80
77
|
name = job[:name]
|
81
78
|
changes = nil
|
82
|
-
|
83
|
-
@generator[:jobs].each do |gen|
|
79
|
+
@pull_generator[:value][:jobs].each do |gen|
|
84
80
|
changes = gen[name.to_sym] if gen.is_a?(Hash) && gen.keys[0] == name.to_sym
|
85
81
|
end
|
86
82
|
# Apply changes
|
@@ -22,20 +22,44 @@
|
|
22
22
|
|
23
23
|
module JenkinsPipelineBuilder
|
24
24
|
class PullRequestGenerator
|
25
|
-
attr_reader :purge
|
26
|
-
|
27
|
-
|
25
|
+
attr_reader :purge, :create, :jobs, :project, :generator, :pull_generator, :errors, :pull_requests
|
26
|
+
|
27
|
+
def initialize(project, generator)
|
28
|
+
@project = project
|
29
|
+
@generator = generator
|
28
30
|
|
29
|
-
def initialize(project, jobs, pull_job)
|
30
31
|
@purge = []
|
31
32
|
@create = []
|
32
|
-
@jobs = {}
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
@errors = {}
|
35
|
+
@pull_generator = find
|
36
|
+
success, payload = compile_generator
|
37
|
+
unless success
|
38
|
+
@errors[@pull_generator[:name]] = payload
|
39
|
+
return false
|
40
|
+
end
|
41
|
+
@jobs = filter_jobs
|
42
|
+
|
43
|
+
# old init
|
44
|
+
@pull_requests = check_for_pull payload
|
45
|
+
find_old_pull_requests
|
46
|
+
generate_pull_requests
|
47
|
+
|
48
|
+
@generator.job_collection.collection.merge! @jobs
|
49
|
+
@errors.merge! create_jobs
|
50
|
+
|
51
|
+
purge_jobs
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid?
|
55
|
+
errors.empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def generate_pull_requests
|
61
|
+
@pull_requests.each do |number|
|
62
|
+
req = JenkinsPipelineBuilder::PullRequest.new(project, number, jobs, @pull_generator)
|
39
63
|
@jobs.merge! req.jobs
|
40
64
|
project_new = req.project
|
41
65
|
|
@@ -45,7 +69,63 @@ module JenkinsPipelineBuilder
|
|
45
69
|
end
|
46
70
|
end
|
47
71
|
|
48
|
-
|
72
|
+
def purge_jobs
|
73
|
+
purge.each do |purge_job|
|
74
|
+
jobs = JenkinsPipelineBuilder.client.job.list "#{purge_job}.*"
|
75
|
+
jobs.each do |job|
|
76
|
+
JenkinsPipelineBuilder.client.job.delete job
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_jobs
|
82
|
+
errors = {}
|
83
|
+
create.each do |pull_project|
|
84
|
+
success, compiled_project = generator.resolve_project(pull_project)
|
85
|
+
compiled_project[:value][:jobs].each do |i|
|
86
|
+
job = i[:result]
|
87
|
+
job = Job.new job
|
88
|
+
success, payload = job.create_or_update
|
89
|
+
errors[job.name] = payload unless success
|
90
|
+
end
|
91
|
+
end
|
92
|
+
errors
|
93
|
+
end
|
94
|
+
|
95
|
+
def filter_jobs
|
96
|
+
jobs = {}
|
97
|
+
pull_jobs = pull_generator[:value][:jobs] || []
|
98
|
+
pull_jobs.each do |job|
|
99
|
+
if job.is_a? String
|
100
|
+
jobs[job.to_s] = generator.job_collection.collection[job.to_s]
|
101
|
+
else
|
102
|
+
jobs[job.keys.first.to_s] = generator.job_collection.collection[job.keys.first.to_s]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
fail 'No jobs found for pull request' if jobs.empty?
|
106
|
+
jobs
|
107
|
+
end
|
108
|
+
|
109
|
+
def compile_generator
|
110
|
+
defaults = generator.job_collection.defaults
|
111
|
+
settings = defaults.nil? ? {} : defaults[:value] || {}
|
112
|
+
compiler = Compiler.new generator
|
113
|
+
settings = compiler.get_settings_bag(project, settings)
|
114
|
+
generator.resolve_job_by_name(pull_generator[:name], settings)
|
115
|
+
end
|
116
|
+
|
117
|
+
def find
|
118
|
+
project_jobs = project[:value][:jobs] || []
|
119
|
+
pull_job = nil
|
120
|
+
project_jobs.each do |job|
|
121
|
+
job = job.keys.first if job.is_a? Hash
|
122
|
+
job = generator.job_collection.collection[job.to_s]
|
123
|
+
|
124
|
+
pull_job = job if job[:value][:job_type] == 'pull_request_generator'
|
125
|
+
end
|
126
|
+
fail 'No jobs of type pull_request_generator found' unless pull_job
|
127
|
+
pull_job
|
128
|
+
end
|
49
129
|
|
50
130
|
# Check for Github Pull Requests
|
51
131
|
#
|
@@ -64,10 +144,10 @@ module JenkinsPipelineBuilder
|
|
64
144
|
pulls.map { |p| p['number'] }
|
65
145
|
end
|
66
146
|
|
67
|
-
|
68
|
-
def purge_old(pull_requests, project)
|
147
|
+
def find_old_pull_requests
|
69
148
|
reqs = pull_requests.clone.map { |req| "#{project[:name]}-PR#{req}" }
|
70
149
|
# Read File
|
150
|
+
# FIXME: Shouldn't this be opening just with read permissions?
|
71
151
|
old_requests = File.new('pull_requests.csv', 'a+').read.split(',')
|
72
152
|
|
73
153
|
# Pop off current pull requests
|
@@ -187,26 +187,16 @@ module JenkinsPipelineBuilder
|
|
187
187
|
'Status' => { 'stapler-class' => 'hudson.views.StatusColumn', 'kind' => 'hudson.views.StatusColumn' },
|
188
188
|
'Weather' => { 'stapler-class' => 'hudson.views.WeatherColumn', 'kind' => 'hudson.views.WeatherColumn' },
|
189
189
|
'Name' => { 'stapler-class' => 'hudson.views.JobColumn', 'kind' => 'hudson.views.JobColumn' },
|
190
|
-
'Last Success' => {
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
'Last
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
'
|
199
|
-
|
200
|
-
'kind' => 'hudson.views.LastDurationColumn'
|
201
|
-
},
|
202
|
-
'Build Button' => {
|
203
|
-
'stapler-class' => 'hudson.views.BuildButtonColumn',
|
204
|
-
'kind' => 'hudson.views.BuildButtonColumn'
|
205
|
-
},
|
206
|
-
'Categorized - Job' => {
|
207
|
-
'stapler-class' => 'org.jenkinsci.plugins.categorizedview.IndentedJobColumn',
|
208
|
-
'kind' => 'org.jenkinsci.plugins.categorizedview.IndentedJobColumn'
|
209
|
-
}
|
190
|
+
'Last Success' => { 'stapler-class' => 'hudson.views.LastSuccessColumn',
|
191
|
+
'kind' => 'hudson.views.LastSuccessColumn' },
|
192
|
+
'Last Failure' => { 'stapler-class' => 'hudson.views.LastFailureColumn',
|
193
|
+
'kind' => 'hudson.views.LastFailureColumn' },
|
194
|
+
'Last Duration' => { 'stapler-class' => 'hudson.views.LastDurationColumn',
|
195
|
+
'kind' => 'hudson.views.LastDurationColumn' },
|
196
|
+
'Build Button' => { 'stapler-class' => 'hudson.views.BuildButtonColumn',
|
197
|
+
'kind' => 'hudson.views.BuildButtonColumn' },
|
198
|
+
'Categorized - Job' => { 'stapler-class' => 'org.jenkinsci.plugins.categorizedview.IndentedJobColumn',
|
199
|
+
'kind' => 'org.jenkinsci.plugins.categorizedview.IndentedJobColumn' }
|
210
200
|
}
|
211
201
|
end
|
212
202
|
|
@@ -9,18 +9,26 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
9
9
|
log_location: '/dev/null'
|
10
10
|
}
|
11
11
|
end
|
12
|
-
let(:
|
13
|
-
let(:
|
12
|
+
let(:generator) { double(job_collection: double(collection: job_collection)) }
|
13
|
+
let(:compiler) { JenkinsPipelineBuilder::Compiler.new generator }
|
14
14
|
let(:settings_global) { { name: 'global', description: 'Do not edit this job through the web!', discard_days: '14', pipeline_repo: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', pipeline_branch: 'master' } }
|
15
15
|
let(:settings_bag) { { name: 'DummyPipeline', description: 'Do not edit this job through the web!', discard_days: '14', pipeline_repo: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', pipeline_branch: 'master' } }
|
16
|
-
let(:job0) { { name: '{{name}}-00', description: '{{description}}', scm_provider: 'git', scm_url: '{{pipeline_repo}}', scm_branch: '{{pipeline_branch}}', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running {{name}}'\necho 'About to run {{job@{{name}}-01}}'\n" }], publishers: [{ downstream: { project: '{{job@{{name}}-01}}' } }] } }
|
17
|
-
let(:job0_compiled) { { name: 'DummyPipeline-00', description: 'Do not edit this job through the web!', scm_provider: 'git', scm_url: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', scm_branch: 'master', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running DummyPipeline'\necho 'About to run DummyPipeline-02'\n" }], publishers: [{ downstream: { project: 'DummyPipeline-02' } }] } }
|
18
|
-
let(:job2) { { name: '{{name}}-02', description: '{{description}}', scm_provider: 'git', scm_url: '{{pipeline_repo}}', scm_branch: '{{pipeline_branch}}', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running {{name}}'" }] } }
|
19
|
-
let(:job2_compiled) { { name: 'DummyPipeline-02', description: 'Do not edit this job through the web!', scm_provider: 'git', scm_url: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', scm_branch: 'master', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running DummyPipeline'" }] } }
|
20
16
|
let(:job_collection) { { '{{name}}-00' => { name: '{{name}}-00', type: :job, value: { name: '{{name}}-00', description: '{{description}}', scm_provider: 'git', scm_url: '{{pipeline_repo}}', scm_branch: '{{pipeline_branch}}', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running {{name}}'\necho 'About to run {{job@{{name}}-01}}'\n" }], publishers: [{ downstream: { project: '{{job@{{name}}-01}}' } }] } }, '{{name}}-01' => { name: '{{name}}-01', type: :job, value: { name: '{{name}}-02', description: '{{description}}', scm_provider: 'git', scm_url: '{{pipeline_repo}}', scm_branch: '{{pipeline_branch}}', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running {{name}}'" }] }, job_name: '{{name}}-02' }, 'global' => { name: 'global', type: :defaults, value: { name: 'global', description: 'Do not edit this job through the web!', discard_days: '14', pipeline_repo: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', pipeline_branch: 'master' } }, 'DummyPipeline' => { name: 'DummyPipeline', type: :project, value: { name: 'DummyPipeline', jobs: [{ '{{name}}-00' => {}, result: { name: 'DummyPipeline-00', description: 'Do not edit this job through the web!', scm_provider: 'git', scm_url: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', scm_branch: 'master', scm_params: { remote_name: 'origin', skip_tag: true }, wrappers: [{ ansicolor: true }], builders: [{ shell_command: "echo 'Running DummyPipeline'\necho 'About to run DummyPipeline-02'\n" }], publishers: [{ downstream: { project: 'DummyPipeline-02' } }] } }, { '{{name}}-01' => { job_name: '{{name}}-02' } }] }, settings: { name: 'DummyPipeline', description: 'Do not edit this job through the web!', discard_days: '14', pipeline_repo: 'git@github.com:constantcontact/jenkins_pipeline_builder.git', pipeline_branch: 'master' } } } }
|
21
17
|
|
22
18
|
describe '#get_settings_bag' do
|
23
19
|
it 'merge settings' do
|
20
|
+
settings_project = {
|
21
|
+
name: 'DummyPipeline',
|
22
|
+
type: :project,
|
23
|
+
value: {
|
24
|
+
name: 'DummyPipeline',
|
25
|
+
jobs: [
|
26
|
+
'{{name}}-00',
|
27
|
+
{ '{{name}}-01' => { job_name: '{{name}}-02' }
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
31
|
+
}
|
24
32
|
settings = compiler.get_settings_bag(settings_project, settings_global)
|
25
33
|
expect(settings).to eq(settings_bag)
|
26
34
|
end
|
@@ -28,13 +36,67 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
28
36
|
|
29
37
|
describe '#compile' do
|
30
38
|
it 'compiles a job with a name change' do
|
31
|
-
|
32
|
-
|
39
|
+
job = {
|
40
|
+
name: '{{name}}-02',
|
41
|
+
description: '{{description}}',
|
42
|
+
scm_provider: 'git',
|
43
|
+
scm_url: '{{pipeline_repo}}',
|
44
|
+
scm_branch: '{{pipeline_branch}}',
|
45
|
+
scm_params: {
|
46
|
+
remote_name: 'origin',
|
47
|
+
skip_tag: true
|
48
|
+
},
|
49
|
+
wrappers: [{ ansicolor: true }],
|
50
|
+
builders: [{ shell_command: "echo 'Running {{name}}'" }]
|
51
|
+
}
|
52
|
+
job_compiled = {
|
53
|
+
name: 'DummyPipeline-02',
|
54
|
+
description: 'Do not edit this job through the web!',
|
55
|
+
scm_provider: 'git',
|
56
|
+
scm_url: 'git@github.com:constantcontact/jenkins_pipeline_builder.git',
|
57
|
+
scm_branch: 'master',
|
58
|
+
scm_params: {
|
59
|
+
remote_name: 'origin',
|
60
|
+
skip_tag: true
|
61
|
+
},
|
62
|
+
wrappers: [{ ansicolor: true }],
|
63
|
+
builders: [{ shell_command: "echo 'Running DummyPipeline'" }]
|
64
|
+
}
|
65
|
+
result = compiler.compile(job, settings_bag)
|
66
|
+
expect(result[1]).to eq(job_compiled)
|
33
67
|
end
|
34
68
|
|
35
69
|
it 'compiles a job with a downstream name change' do
|
36
|
-
|
37
|
-
|
70
|
+
job = {
|
71
|
+
name: '{{name}}-00',
|
72
|
+
description: '{{description}}',
|
73
|
+
scm_provider: 'git',
|
74
|
+
scm_url: '{{pipeline_repo}}',
|
75
|
+
scm_branch: '{{pipeline_branch}}',
|
76
|
+
scm_params: {
|
77
|
+
remote_name: 'origin',
|
78
|
+
skip_tag: true
|
79
|
+
},
|
80
|
+
wrappers: [{ ansicolor: true }],
|
81
|
+
builders: [{ shell_command: "echo 'Running {{name}}'\necho 'About to run {{job@{{name}}-01}}'\n" }],
|
82
|
+
publishers: [{ downstream: { project: '{{job@{{name}}-01}}' } }]
|
83
|
+
}
|
84
|
+
job_compiled = {
|
85
|
+
name: 'DummyPipeline-00',
|
86
|
+
description: 'Do not edit this job through the web!',
|
87
|
+
scm_provider: 'git',
|
88
|
+
scm_url: 'git@github.com:constantcontact/jenkins_pipeline_builder.git',
|
89
|
+
scm_branch: 'master',
|
90
|
+
scm_params: {
|
91
|
+
remote_name: 'origin',
|
92
|
+
skip_tag: true
|
93
|
+
},
|
94
|
+
wrappers: [{ ansicolor: true }],
|
95
|
+
builders: [{ shell_command: "echo 'Running DummyPipeline'\necho 'About to run DummyPipeline-02'\n" }],
|
96
|
+
publishers: [{ downstream: { project: 'DummyPipeline-02' } }]
|
97
|
+
}
|
98
|
+
result = compiler.compile(job, settings_bag)
|
99
|
+
expect(result[1]).to eq(job_compiled)
|
38
100
|
end
|
39
101
|
|
40
102
|
it 'compiles an enabled job with a string parameter' do
|
@@ -44,7 +106,7 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
44
106
|
triggers: [{ periodic_build: 'this_is_a_var' }] }
|
45
107
|
settings_bag = { var: 'this_is_a_var', name: 'name' }
|
46
108
|
|
47
|
-
result = compiler.compile(my_job, settings_bag
|
109
|
+
result = compiler.compile(my_job, settings_bag)
|
48
110
|
expect(result[1]).to eq(compiled_job)
|
49
111
|
end
|
50
112
|
end
|
@@ -53,8 +115,7 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
53
115
|
it 'generates correct new jobs with true' do
|
54
116
|
item = { enabled: '{{use1}}', parameters: { rootPom: 'path_to_pomasd' } }
|
55
117
|
settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: true }
|
56
|
-
|
57
|
-
success, item = compiler.handle_enable(item, settings, job_collection)
|
118
|
+
success, item = compiler.handle_enable(item, settings)
|
58
119
|
expect(success).to be true
|
59
120
|
expect(item).to eq(rootPom: 'path_to_pomasd')
|
60
121
|
end
|
@@ -62,8 +123,7 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
62
123
|
it 'generates correct new jobs when the params are a string' do
|
63
124
|
item = { enabled: '{{use1}}', parameters: 'path_to_pomasd' }
|
64
125
|
settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: true }
|
65
|
-
|
66
|
-
success, item = compiler.handle_enable(item, settings, job_collection)
|
126
|
+
success, item = compiler.handle_enable(item, settings)
|
67
127
|
expect(success).to be true
|
68
128
|
expect(item).to eq('path_to_pomasd')
|
69
129
|
end
|
@@ -71,8 +131,7 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
71
131
|
it 'generates correct new jobs with false' do
|
72
132
|
item = { enabled: '{{use1}}', parameters: { rootPom: 'path_to_pomasd' } }
|
73
133
|
settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: false }
|
74
|
-
|
75
|
-
success, item = compiler.handle_enable(item, settings, job_collection)
|
134
|
+
success, item = compiler.handle_enable(item, settings)
|
76
135
|
expect(success).to be true
|
77
136
|
expect(item).to eq({})
|
78
137
|
end
|
@@ -80,16 +139,14 @@ describe JenkinsPipelineBuilder::Compiler do
|
|
80
139
|
it 'fails when value not found' do
|
81
140
|
item = { enabled: '{{use_fail}}', parameters: { rootPom: 'path_to_pomasd' } }
|
82
141
|
settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use1: true }
|
83
|
-
|
84
|
-
success, _ = compiler.handle_enable(item, settings, job_collection)
|
142
|
+
success, _ = compiler.handle_enable(item, settings)
|
85
143
|
expect(success).to be false
|
86
144
|
end
|
87
145
|
|
88
146
|
it 'removes empty builders' do
|
89
147
|
item = { enabled: '{{use}}', parameters: { rootPom: 'one' } }
|
90
148
|
settings = { name: 'PushTest', description: 'DB Pipeline tooling', git_repo: 'git@github.roving.com:devops/DBPipeline.git', git_branch: 'master', excluded_user: 'buildmaster', hipchat_room: 'CD Builds', hipchat_auth_token: 'f3e98ed54605b36f56dd2c562e3775', discard_days: '30', discard_number: '100', maven_name: 'tools-maven-3.0.3', hipchat_jenkins_url: 'https://cd-jenkins.ad.prodcc.net/', use: false }
|
91
|
-
|
92
|
-
success, result = compiler.compile_hash(item, settings, job_collection)
|
149
|
+
success, result = compiler.handle_enable(item, settings)
|
93
150
|
expect(success).to be true
|
94
151
|
expect(result).to eq({})
|
95
152
|
end
|