jenkins_pipeline_builder 1.7.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.rubocop_todo.yml +0 -6
- data/jenkins_pipeline_builder.gemspec +1 -2
- data/lib/jenkins_pipeline_builder.rb +1 -1
- data/lib/jenkins_pipeline_builder/cli/helper.rb +3 -2
- data/lib/jenkins_pipeline_builder/cli/list.rb +1 -0
- data/lib/jenkins_pipeline_builder/compiler.rb +14 -1
- data/lib/jenkins_pipeline_builder/extension_set.rb +5 -1
- data/lib/jenkins_pipeline_builder/extensions.rb +4 -0
- data/lib/jenkins_pipeline_builder/extensions/helpers/publishers/cobertura_report_helper.rb +1 -0
- data/lib/jenkins_pipeline_builder/extensions/job_attributes.rb +1 -0
- data/lib/jenkins_pipeline_builder/extensions/wrappers.rb +2 -1
- data/lib/jenkins_pipeline_builder/generator.rb +4 -0
- data/lib/jenkins_pipeline_builder/job.rb +3 -0
- data/lib/jenkins_pipeline_builder/job_collection.rb +2 -0
- data/lib/jenkins_pipeline_builder/module_registry.rb +4 -0
- data/lib/jenkins_pipeline_builder/promotion.rb +1 -0
- data/lib/jenkins_pipeline_builder/pull_request_generator.rb +1 -0
- data/lib/jenkins_pipeline_builder/remote_dependencies.rb +2 -2
- data/lib/jenkins_pipeline_builder/utils.rb +8 -7
- data/lib/jenkins_pipeline_builder/version.rb +1 -1
- data/lib/jenkins_pipeline_builder/view.rb +3 -1
- data/spec/lib/jenkins_pipeline_builder/cli/helper_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/compiler_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extension_dsl_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extension_set_spec.rb +2 -2
- data/spec/lib/jenkins_pipeline_builder/extensions/build_steps_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/builders_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/job_attributes_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/promotion_conditions_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/publishers_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/registered_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/triggers_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions/wrappers_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/extensions_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/generator_spec.rb +63 -32
- data/spec/lib/jenkins_pipeline_builder/job_collection_spec.rb +2 -2
- data/spec/lib/jenkins_pipeline_builder/job_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/module_registry_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/promotion_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/pull_request_generator_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/spec_helper.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/utils_spec.rb +1 -1
- data/spec/lib/jenkins_pipeline_builder/view_spec.rb +2 -2
- data/spec/requests/pipeline_spec.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a89e7eaacca4711e8cfba8ba745799d5b4eb01014a5a78740ff74ab606595f7a
|
4
|
+
data.tar.gz: d9adb6f45f1d7be7ea7c1815e491338ad32bfc7b15859c92955482d550930332
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19c78e7c9801ce59933cd96b37cf259d76d0b9c0e427b2c6dcd3b40491d7e77efb6c22dd09f384cb1221ba062e3bc614bb9ecd4f2c7920f028bed18f7ced6079
|
7
|
+
data.tar.gz: 2fd655ec2dd99d45ddc6f2f794cf6b6b7ecf469f8b8eb4fe22aeb74f5f9791f42b06e5ffb37087e2d9bda7cb35c512e17915ebbe78055984299c97d235870025
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -24,12 +24,6 @@ Metrics/BlockLength:
|
|
24
24
|
# Offense count: 5
|
25
25
|
# Cop supports --auto-correct.
|
26
26
|
# Configuration parameters: AutoCorrect.
|
27
|
-
Performance/HashEachMethods:
|
28
|
-
Exclude:
|
29
|
-
- 'lib/jenkins_pipeline_builder/cli/list.rb'
|
30
|
-
- 'lib/jenkins_pipeline_builder/compiler.rb'
|
31
|
-
- 'lib/jenkins_pipeline_builder/extensions.rb'
|
32
|
-
- 'lib/jenkins_pipeline_builder/utils.rb'
|
33
27
|
|
34
28
|
# Offense count: 1
|
35
29
|
# Configuration parameters: MinBodyLength.
|
@@ -80,6 +80,7 @@ module JenkinsPipelineBuilder
|
|
80
80
|
def self.process_creds_file(file)
|
81
81
|
return load File.expand_path(file) if file.end_with? 'rb'
|
82
82
|
return self.jenkins_api_creds = JSON.parse(IO.read(File.expand_path(file))) if file.end_with? 'json'
|
83
|
+
|
83
84
|
self.jenkins_api_creds = YAML.load_file(File.expand_path(file))
|
84
85
|
end
|
85
86
|
|
@@ -97,14 +98,13 @@ module JenkinsPipelineBuilder
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
100
|
-
private_class_method
|
101
|
-
|
102
101
|
def self.find_default_file
|
103
102
|
default_file_name = "#{ENV['HOME']}/.jenkins_api_client/login"
|
104
103
|
|
105
104
|
found_suffix = nil
|
106
105
|
DEFAULT_FILE_FORMATS.each do |suffix|
|
107
106
|
next unless File.exist?("#{default_file_name}.#{suffix}")
|
107
|
+
|
108
108
|
if !found_suffix
|
109
109
|
found_suffix = suffix
|
110
110
|
else
|
@@ -118,6 +118,7 @@ module JenkinsPipelineBuilder
|
|
118
118
|
def self.logger
|
119
119
|
JenkinsPipelineBuilder.logger
|
120
120
|
end
|
121
|
+
private_class_method :find_default_file, :logger
|
121
122
|
end
|
122
123
|
end
|
123
124
|
end
|
@@ -33,11 +33,14 @@ module JenkinsPipelineBuilder
|
|
33
33
|
item = item_bag[:value]
|
34
34
|
bag = {}
|
35
35
|
return unless item.is_a?(Hash)
|
36
|
+
|
36
37
|
item.keys.each do |k|
|
37
38
|
val = item[k]
|
38
39
|
next unless val.is_a? String
|
40
|
+
|
39
41
|
new_value = resolve_value(val, settings_bag)
|
40
42
|
return nil if new_value.nil?
|
43
|
+
|
41
44
|
bag[k] = new_value
|
42
45
|
end
|
43
46
|
my_settings_bag = settings_bag.clone
|
@@ -48,7 +51,7 @@ module JenkinsPipelineBuilder
|
|
48
51
|
new_item = compile(item, settings)
|
49
52
|
[true, new_item]
|
50
53
|
rescue StandardError => e
|
51
|
-
|
54
|
+
[false, [e.message]]
|
52
55
|
end
|
53
56
|
|
54
57
|
def compile(item, settings = {})
|
@@ -67,10 +70,12 @@ module JenkinsPipelineBuilder
|
|
67
70
|
|
68
71
|
def handle_enable(item, settings)
|
69
72
|
return item unless item.is_a? Hash
|
73
|
+
|
70
74
|
if enable_block_present? item
|
71
75
|
enabled_switch = resolve_value(item[:enabled], settings)
|
72
76
|
return {} if enabled_switch == 'false'
|
73
77
|
raise "Invalid value for #{item[:enabled]}: #{enabled_switch}" if enabled_switch != 'true'
|
78
|
+
|
74
79
|
if item[:parameters].is_a? Hash
|
75
80
|
item = item.merge item[:parameters]
|
76
81
|
item.delete :parameters
|
@@ -105,8 +110,10 @@ module JenkinsPipelineBuilder
|
|
105
110
|
|
106
111
|
def compile_array_item(item, settings, array)
|
107
112
|
raise "Found a nil value when processing following array:\n #{array.inspect}" if item.nil?
|
113
|
+
|
108
114
|
payload = compile(item, settings)
|
109
115
|
raise "Failed to resolve:\n===>item #{item}\n\n===>of list: #{array.inspect}" if payload.nil?
|
116
|
+
|
110
117
|
payload
|
111
118
|
end
|
112
119
|
|
@@ -114,8 +121,10 @@ module JenkinsPipelineBuilder
|
|
114
121
|
if value.nil?
|
115
122
|
raise "key: #{key} has a nil value, this is often a yaml syntax error. Skipping children and siblings"
|
116
123
|
end
|
124
|
+
|
117
125
|
payload = compile(value, settings)
|
118
126
|
raise "Failed to resolve:\n===>key: #{key}\n\n===>value: #{value} payload" if payload.nil?
|
127
|
+
|
119
128
|
payload
|
120
129
|
end
|
121
130
|
|
@@ -135,6 +144,7 @@ module JenkinsPipelineBuilder
|
|
135
144
|
pull_job = value.to_s.match(/{{pull@(.*)}}/)
|
136
145
|
if pull_job
|
137
146
|
return pull_job[1] unless settings[:pull_request_number]
|
147
|
+
|
138
148
|
value = pull_job[1]
|
139
149
|
end
|
140
150
|
|
@@ -151,16 +161,19 @@ module JenkinsPipelineBuilder
|
|
151
161
|
vars.select! do |var|
|
152
162
|
var_val = settings[var]
|
153
163
|
raise "Could not find defined substitution variable: #{var}" if var_val.nil?
|
164
|
+
|
154
165
|
value_s.gsub!("{{#{var}}}", var_val.to_s)
|
155
166
|
var_val.nil?
|
156
167
|
end
|
157
168
|
return nil if vars.count != 0
|
169
|
+
|
158
170
|
value_s
|
159
171
|
end
|
160
172
|
|
161
173
|
def correct_job_names!(value)
|
162
174
|
vars = value.scan(/{{job@(.*)}}/).flatten
|
163
175
|
return unless vars.count > 0
|
176
|
+
|
164
177
|
vars.select! do |var|
|
165
178
|
var_val = job_collection[var.to_s]
|
166
179
|
value.gsub!("{{job@#{var}}}", var_val[:value][:name]) unless var_val.nil?
|
@@ -12,6 +12,7 @@ module JenkinsPipelineBuilder
|
|
12
12
|
SET_METHODS.each do |method_name|
|
13
13
|
define_method method_name do |value = nil|
|
14
14
|
return settings[method_name] if value.nil?
|
15
|
+
|
15
16
|
settings[method_name] = value
|
16
17
|
end
|
17
18
|
end
|
@@ -35,7 +36,6 @@ module JenkinsPipelineBuilder
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def installed_version=(version)
|
38
|
-
version = version.match(/\d+\.\d+(\.\d+)?/)
|
39
39
|
@version = Gem::Version.new version
|
40
40
|
end
|
41
41
|
|
@@ -53,9 +53,11 @@ module JenkinsPipelineBuilder
|
|
53
53
|
|
54
54
|
def installed_version
|
55
55
|
return @version if @version
|
56
|
+
|
56
57
|
reg = JenkinsPipelineBuilder.registry
|
57
58
|
version = reg.versions[settings[:plugin_id]]
|
58
59
|
raise "Plugin #{settings[:name]} is not installed (plugin_id: #{settings[:plugin_id]})" if version.nil?
|
60
|
+
|
59
61
|
self.installed_version = version
|
60
62
|
@version
|
61
63
|
end
|
@@ -103,6 +105,7 @@ module JenkinsPipelineBuilder
|
|
103
105
|
end
|
104
106
|
unless block
|
105
107
|
raise "no block found for version #{version}" unless blocks.key version
|
108
|
+
|
106
109
|
return blocks[version][:block]
|
107
110
|
end
|
108
111
|
store_xml version, block, path
|
@@ -122,6 +125,7 @@ module JenkinsPipelineBuilder
|
|
122
125
|
end
|
123
126
|
|
124
127
|
return instance_variable_get(method_name) unless block
|
128
|
+
|
125
129
|
blocks[version] = {} unless blocks[version]
|
126
130
|
blocks[version][method_name] = block
|
127
131
|
end
|
@@ -40,6 +40,7 @@ module JenkinsPipelineBuilder
|
|
40
40
|
EXT_METHODS.keys.each do |method_name|
|
41
41
|
define_method method_name do |value = nil|
|
42
42
|
return instance_variable_get("@#{method_name}") if value.nil?
|
43
|
+
|
43
44
|
instance_variable_set("@#{method_name}", value)
|
44
45
|
end
|
45
46
|
end
|
@@ -59,6 +60,7 @@ module JenkinsPipelineBuilder
|
|
59
60
|
def execute(value, n_xml)
|
60
61
|
errors = check_parameters value
|
61
62
|
raise ArgumentError, errors.join("\n") if errors.any?
|
63
|
+
|
62
64
|
unless path
|
63
65
|
raise ArgumentError, %(Extension #{name} has no valid path
|
64
66
|
Check ModuleRegistry#entries and the definition of the extension
|
@@ -76,9 +78,11 @@ module JenkinsPipelineBuilder
|
|
76
78
|
def check_parameters(value)
|
77
79
|
return [] if parameters && parameters.empty?
|
78
80
|
return [] unless value.is_a? Hash
|
81
|
+
|
79
82
|
errors = []
|
80
83
|
value.each_key do |key|
|
81
84
|
next if parameters && parameters.include?(key)
|
85
|
+
|
82
86
|
errors << "Extension #{name} does not support parameter #{key}"
|
83
87
|
end
|
84
88
|
errors
|
@@ -227,6 +227,7 @@ job_attribute do
|
|
227
227
|
if params[:changelog_to_branch]
|
228
228
|
opts = params[:changelog_to_branch]
|
229
229
|
raise 'remote and branch are required for changelog_to_branch' unless opts[:remote] && opts[:branch]
|
230
|
+
|
230
231
|
send('hudson.plugins.git.extensions.impl.ChangelogToBranch') do
|
231
232
|
options do
|
232
233
|
compareRemote opts[:remote]
|
@@ -26,7 +26,6 @@ wrapper do
|
|
26
26
|
announced false
|
27
27
|
jenkins_name 'Color ANSI Console Output'
|
28
28
|
description 'This plugin adds support for ANSI escape sequences, including color, to Console Output.'
|
29
|
-
|
30
29
|
xml do |_|
|
31
30
|
send('hudson.plugins.ansicolor.AnsiColorBuildWrapper') do
|
32
31
|
colorMapName 'xterm'
|
@@ -99,6 +98,7 @@ wrapper do
|
|
99
98
|
passwords = wrapper
|
100
99
|
end
|
101
100
|
break unless passwords
|
101
|
+
|
102
102
|
passwordEntries do
|
103
103
|
passwords.each do |password|
|
104
104
|
EnvInjectPasswordEntry do
|
@@ -148,6 +148,7 @@ wrapper do
|
|
148
148
|
resolvePattern
|
149
149
|
matrixParams wrapper[:properties]
|
150
150
|
deployBuildInfo wrapper[:'publish-build-info']
|
151
|
+
useSpecs false
|
151
152
|
includeEnvVars false
|
152
153
|
envVarsPatterns do
|
153
154
|
includePatterns
|
@@ -66,6 +66,7 @@ module JenkinsPipelineBuilder
|
|
66
66
|
errors = []
|
67
67
|
pr_generator.open_prs.each do |pr|
|
68
68
|
next if base_branch_only && defaults[:git_branch] != pr[:base]
|
69
|
+
|
69
70
|
pr_generator.convert! job_collection, pr[:number]
|
70
71
|
error = publish(project_name)
|
71
72
|
errors << error unless error.empty?
|
@@ -105,6 +106,7 @@ module JenkinsPipelineBuilder
|
|
105
106
|
def resolve_job_by_name(name, settings = {})
|
106
107
|
job = job_collection.get_item(name)
|
107
108
|
raise "Failed to locate job by name '#{name}'" if job.nil?
|
109
|
+
|
108
110
|
job_value = job[:value]
|
109
111
|
logger.debug "Compiling job #{name}"
|
110
112
|
compiler = JenkinsPipelineBuilder::Compiler.new self
|
@@ -214,6 +216,7 @@ module JenkinsPipelineBuilder
|
|
214
216
|
# A hash of promoted_builds names => associated job names
|
215
217
|
promotion_job_pairs = jobs.each_with_object({}) do |j, acc|
|
216
218
|
next unless j[:result][:promoted_builds]
|
219
|
+
|
217
220
|
j[:result][:promoted_builds].each do |promotion_name|
|
218
221
|
acc[promotion_name] = j[:result][:name]
|
219
222
|
end
|
@@ -238,6 +241,7 @@ module JenkinsPipelineBuilder
|
|
238
241
|
logger.info "Processing #{i}"
|
239
242
|
job = i[:result]
|
240
243
|
raise "Result is empty for #{i}" if job.nil?
|
244
|
+
|
241
245
|
job = Job.new job
|
242
246
|
success, payload = job.create_or_update
|
243
247
|
errors[job.name] = payload unless success
|
@@ -17,6 +17,7 @@ module JenkinsPipelineBuilder
|
|
17
17
|
def create_or_update
|
18
18
|
success, payload = to_xml
|
19
19
|
return success, payload unless success
|
20
|
+
|
20
21
|
xml = payload
|
21
22
|
return local_output(xml) if JenkinsPipelineBuilder.debug || JenkinsPipelineBuilder.file_mode
|
22
23
|
|
@@ -31,6 +32,7 @@ module JenkinsPipelineBuilder
|
|
31
32
|
job[:job_type] = 'free_style' unless job[:job_type]
|
32
33
|
type = job[:job_type]
|
33
34
|
return false, "Job type: #{type} is not one of #{job_methods.join(', ')}" unless known_type? type
|
35
|
+
|
34
36
|
@xml = setup_freestyle_base(job)
|
35
37
|
payload = send("update_#{type}")
|
36
38
|
|
@@ -109,6 +111,7 @@ module JenkinsPipelineBuilder
|
|
109
111
|
if params.key?(:template)
|
110
112
|
template_name = params[:template]
|
111
113
|
raise "Job template '#{template_name}' can't be resolved." unless @job_templates.key?(template_name)
|
114
|
+
|
112
115
|
params.delete(:template)
|
113
116
|
template = @job_templates[template_name]
|
114
117
|
params = template.deep_merge(params)
|
@@ -108,6 +108,7 @@ module JenkinsPipelineBuilder
|
|
108
108
|
# skip if the existing item is local and the new item is remote
|
109
109
|
return if remote && !existing_remote
|
110
110
|
raise "Duplicate item with name '#{name}' was detected." unless existing_remote && !remote
|
111
|
+
|
111
112
|
# override if the existing item is remote and the new is local
|
112
113
|
logger.info "Duplicate item with name '#{name}' was detected from the remote folder."
|
113
114
|
end
|
@@ -118,6 +119,7 @@ module JenkinsPipelineBuilder
|
|
118
119
|
path = "#{path}/extensions"
|
119
120
|
path = File.expand_path(path, Dir.getwd)
|
120
121
|
return unless File.directory?(path)
|
122
|
+
|
121
123
|
logger.info "Loading extensions from folder #{path}"
|
122
124
|
logger.info Dir.glob("#{path}/*.rb").inspect
|
123
125
|
Dir.glob("#{path}/**/*.rb").each do |file|
|
@@ -29,6 +29,7 @@ module JenkinsPipelineBuilder
|
|
29
29
|
def versions
|
30
30
|
# Return a hash with a default of 1000 so that we'll get the newest in debug
|
31
31
|
return Hash.new { |_| '1000.0' } if JenkinsPipelineBuilder.debug
|
32
|
+
|
32
33
|
@versions ||= JenkinsPipelineBuilder.client.plugin.list_installed
|
33
34
|
end
|
34
35
|
|
@@ -77,6 +78,7 @@ module JenkinsPipelineBuilder
|
|
77
78
|
def get_by_path_collection(path, registry)
|
78
79
|
item = registry[path.shift.to_sym]
|
79
80
|
return item if path.count == 0
|
81
|
+
|
80
82
|
get_by_path_collection(path, item)
|
81
83
|
end
|
82
84
|
|
@@ -88,8 +90,10 @@ module JenkinsPipelineBuilder
|
|
88
90
|
def traverse_registry(registry, params, n_xml, strict = false)
|
89
91
|
params.each do |key, value|
|
90
92
|
next unless registry.is_a? Hash
|
93
|
+
|
91
94
|
unless registry.key? key
|
92
95
|
raise TypeError, "!!!! could not find key #{key} !!!!" if strict
|
96
|
+
|
93
97
|
next
|
94
98
|
end
|
95
99
|
reg_value = registry[key]
|
@@ -31,6 +31,7 @@ module JenkinsPipelineBuilder
|
|
31
31
|
def create(params, job_name)
|
32
32
|
success, payload = prom_to_xml(params)
|
33
33
|
return success, payload unless success
|
34
|
+
|
34
35
|
xml = payload
|
35
36
|
return local_output(xml) if JenkinsPipelineBuilder.debug || JenkinsPipelineBuilder.file_mode
|
36
37
|
|
@@ -37,6 +37,7 @@ module JenkinsPipelineBuilder
|
|
37
37
|
|
38
38
|
def delete_closed_prs
|
39
39
|
return if JenkinsPipelineBuilder.debug
|
40
|
+
|
40
41
|
jobs_to_delete = JenkinsPipelineBuilder.client.job.list "^#{application_name}-PR(\\d+)-(.*)$"
|
41
42
|
open_prs.each do |pr|
|
42
43
|
jobs_to_delete.reject! { |j| j.start_with? "#{application_name}-PR#{pr[:number]}" }
|
@@ -88,8 +88,8 @@ module JenkinsPipelineBuilder
|
|
88
88
|
def download_yaml(url, file, remote_opts = {})
|
89
89
|
entries[url] = file
|
90
90
|
logger.info "Downloading #{url} to #{file}.tar"
|
91
|
-
open("#{file}.tar", 'w') do |local_file|
|
92
|
-
open(
|
91
|
+
File.open("#{file}.tar", 'w') do |local_file|
|
92
|
+
URI.parse(url).open(remote_opts) do |remote_file|
|
93
93
|
local_file.write(Zlib::GzipReader.new(remote_file).read)
|
94
94
|
end
|
95
95
|
end
|
@@ -30,13 +30,14 @@ end
|
|
30
30
|
module JenkinsPipelineBuilder
|
31
31
|
class Utils
|
32
32
|
# Code was duplicated from jeknins_api_client
|
33
|
-
def self.symbolize_keys_deep!(
|
34
|
-
return unless
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
33
|
+
def self.symbolize_keys_deep!(to_symbolize)
|
34
|
+
return unless to_symbolize.is_a?(Hash)
|
35
|
+
|
36
|
+
to_symbolize.keys.each do |k|
|
37
|
+
ks = k.respond_to?(:to_sym) ? k.to_sym : k
|
38
|
+
to_symbolize[ks] = to_symbolize.delete k # Preserve order even when k == ks
|
39
|
+
symbolize_keys_deep! to_symbolize[ks] if to_symbolize[ks].is_a? Hash
|
40
|
+
to_symbolize[ks].each { |item| symbolize_keys_deep!(item) } if to_symbolize[ks].is_a?(Array)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -67,6 +67,7 @@ module JenkinsPipelineBuilder
|
|
67
67
|
def create(params)
|
68
68
|
# Name is a required parameter. Raise an error if not specified
|
69
69
|
raise ArgumentError, 'Name is required for creating view' unless params.is_a?(Hash) && params[:name]
|
70
|
+
|
70
71
|
clean_up_views(params) unless JenkinsPipelineBuilder.debug
|
71
72
|
params[:type] ||= 'listview'
|
72
73
|
create_base_view(params[:name], params[:type], params[:parent_view])
|
@@ -133,7 +134,8 @@ module JenkinsPipelineBuilder
|
|
133
134
|
'dashboardView' => 'hudson.plugins.view.dashboard.Dashboard',
|
134
135
|
'multijobView' => 'com.tikal.jenkins.plugins.multijob.views.MultiJobView'
|
135
136
|
}
|
136
|
-
raise "Type #{type} is not supported by Jenkins." unless types.
|
137
|
+
raise "Type #{type} is not supported by Jenkins." unless types.key?(type)
|
138
|
+
|
137
139
|
types[type]
|
138
140
|
end
|
139
141
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('spec_helper', __dir__)
|
2
2
|
|
3
3
|
describe JenkinsPipelineBuilder::ExtensionSet do
|
4
4
|
subject(:set) { JenkinsPipelineBuilder::ExtensionSet.new('foo') {} }
|
@@ -108,7 +108,7 @@ describe JenkinsPipelineBuilder::ExtensionSet do
|
|
108
108
|
it 'works for snapshot/beta stuff' do
|
109
109
|
ext_versions ['1.9', '2.3']
|
110
110
|
|
111
|
-
set.installed_version = '2.0-SNAPSHOT
|
111
|
+
set.installed_version = '2.0-SNAPSHOT'
|
112
112
|
# Other examples
|
113
113
|
# set.installed_version = '2.0-beta-1'
|
114
114
|
# set.installed_version = '2.0+build.93'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('spec_helper', __dir__)
|
2
2
|
|
3
3
|
describe JenkinsPipelineBuilder::Generator do
|
4
4
|
before :all do
|
@@ -89,31 +89,52 @@ describe JenkinsPipelineBuilder::Generator do
|
|
89
89
|
expect(errors).to be_empty
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
context 'when creating pipeline templates' do
|
93
|
+
before(:each) do
|
94
|
+
tar_path = File.join(__dir__, 'fixtures/generator_tests/template_pipeline/jobs.tar.gz')
|
95
|
+
parsed_url = URI.parse('https://www.test.com')
|
96
|
+
file_contents = Zlib::GzipReader.new(File.open(tar_path)).read
|
97
|
+
file_object = double
|
98
|
+
allow(URI).to receive(:parse).and_return(parsed_url)
|
99
|
+
allow(parsed_url).to receive(:open).and_yield('A String')
|
100
|
+
allow(Zlib::GzipReader).to receive(:new).and_return(file_object)
|
101
|
+
allow(file_object).to receive(:read).and_return(file_contents)
|
102
|
+
end
|
96
103
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
104
|
+
it 'produces no errors while creating pipeline TemplatePipeline' do
|
105
|
+
errors = bootstrap(fixture_path('template_pipeline'), 'TemplatePipeline')
|
106
|
+
expect(errors).to be_empty
|
107
|
+
end
|
101
108
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
109
|
+
it 'overrides the remote dependencies with local ones' do
|
110
|
+
errors = bootstrap(fixture_path('local_override/remote_and_local'), 'TemplatePipeline')
|
111
|
+
expect(errors).to be_empty
|
112
|
+
expect(@generator.job_collection.collection['{{name}}-10'][:value][:description]).to eq('Overridden stuff')
|
113
|
+
end
|
108
114
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
115
|
+
it 'loads extensions in remote dependencies' do
|
116
|
+
errors = bootstrap(fixture_path('template_pipeline'), 'TemplatePipeline')
|
117
|
+
expect(errors).to be_empty
|
118
|
+
expect(@generator.module_registry.registry[:job][:wrappers].keys).to include :test_wrapper
|
119
|
+
@generator.module_registry.registry[:job][:wrappers].delete(:test_wrapper)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'fails to override when there are duplicate local items' do
|
123
|
+
expect { bootstrap(fixture_path('local_override/all_local'), 'TemplatePipeline') }.to raise_error(StandardError)
|
124
|
+
end
|
114
125
|
|
115
|
-
|
116
|
-
|
126
|
+
it 'produces no errors while creating pipeline TemplatePipeline_nested' do
|
127
|
+
tar_path = File.join(__dir__, 'fixtures/generator_tests/template_pipeline_nested/jobs.tar.gz')
|
128
|
+
parsed_url = URI.parse('https://www.test.com')
|
129
|
+
file_contents = Zlib::GzipReader.new(File.open(tar_path)).read
|
130
|
+
file_object = double
|
131
|
+
allow(URI).to receive(:parse).and_return(parsed_url)
|
132
|
+
allow(parsed_url).to receive(:open).and_yield('A String')
|
133
|
+
allow(Zlib::GzipReader).to receive(:new).and_return(file_object)
|
134
|
+
allow(file_object).to receive(:read).and_return(file_contents)
|
135
|
+
errors = bootstrap(fixture_path('template_pipeline_nested'), 'TemplatePipeline_nested')
|
136
|
+
expect(errors).to be_empty
|
137
|
+
end
|
117
138
|
end
|
118
139
|
|
119
140
|
# Things to check for:
|
@@ -136,7 +157,7 @@ describe JenkinsPipelineBuilder::Generator do
|
|
136
157
|
let(:pr_master) { { number: 1, base: 'master' } }
|
137
158
|
let(:pr_not_master) { { number: 2, base: 'not-master' } }
|
138
159
|
let(:open_prs) { [pr_master, pr_not_master] }
|
139
|
-
let(:path) { File.expand_path('
|
160
|
+
let(:path) { File.expand_path('fixtures/generator_tests/pullrequest_pipeline', __dir__) }
|
140
161
|
it 'produces no errors while creating pipeline PullRequest' do
|
141
162
|
job_name = 'PullRequest'
|
142
163
|
pr_generator = double('pr_generator')
|
@@ -195,7 +216,7 @@ describe JenkinsPipelineBuilder::Generator do
|
|
195
216
|
github_site: 'https://github.com',
|
196
217
|
git_org: 'testorg',
|
197
218
|
git_repo_name: 'generator_tests'
|
198
|
-
|
219
|
+
)).and_return(pr_generator)
|
199
220
|
|
200
221
|
expect(pr_generator).to receive(:open_prs).and_return open_prs
|
201
222
|
expect(pr_generator).to receive(:delete_closed_prs)
|
@@ -227,26 +248,26 @@ describe JenkinsPipelineBuilder::Generator do
|
|
227
248
|
end
|
228
249
|
|
229
250
|
it 'loads a yaml collection from a path' do
|
230
|
-
path = File.expand_path('
|
251
|
+
path = File.expand_path('fixtures/generator_tests/test_yaml_files', __dir__)
|
231
252
|
@generator.job_collection.load_from_path path
|
232
253
|
end
|
233
254
|
it 'loads a json collection from a path' do
|
234
|
-
path = File.expand_path('
|
255
|
+
path = File.expand_path('fixtures/generator_tests/test_json_files', __dir__)
|
235
256
|
@generator.job_collection.load_from_path path
|
236
257
|
end
|
237
258
|
it 'loads both yaml and json files from a path' do
|
238
|
-
path = File.expand_path('
|
259
|
+
path = File.expand_path('fixtures/generator_tests/test_combo_files', __dir__)
|
239
260
|
@generator.job_collection.load_from_path path
|
240
261
|
end
|
241
262
|
|
242
263
|
it 'errors when reading a bad yaml file' do
|
243
|
-
path = File.expand_path('
|
264
|
+
path = File.expand_path('fixtures/generator_tests/test_bad_yaml_files', __dir__)
|
244
265
|
expect { @generator.job_collection.load_from_path path }.to raise_error(
|
245
266
|
CustomErrors::ParseError, /There was an error while parsing a file/
|
246
267
|
)
|
247
268
|
end
|
248
269
|
it 'errors when reading a bad json file' do
|
249
|
-
path = File.expand_path('
|
270
|
+
path = File.expand_path('fixtures/generator_tests/test_bad_json_files', __dir__)
|
250
271
|
expect { @generator.job_collection.load_from_path path }.to raise_error(
|
251
272
|
CustomErrors::ParseError, /There was an error while parsing a file/
|
252
273
|
)
|
@@ -258,7 +279,7 @@ describe JenkinsPipelineBuilder::Generator do
|
|
258
279
|
allow(JenkinsPipelineBuilder).to receive(:debug).and_return true
|
259
280
|
job_name = 'test_job'
|
260
281
|
body = ''
|
261
|
-
test_path = File.expand_path('
|
282
|
+
test_path = File.expand_path('fixtures/generator_tests', __dir__)
|
262
283
|
File.open("#{test_path}/#{job_name}.xml", 'r') do |f|
|
263
284
|
f.each_line do |line|
|
264
285
|
body << line
|
@@ -274,7 +295,7 @@ describe JenkinsPipelineBuilder::Generator do
|
|
274
295
|
|
275
296
|
describe '#projects' do
|
276
297
|
it 'returns a list of projects' do
|
277
|
-
path = File.expand_path('
|
298
|
+
path = File.expand_path('fixtures/generator_tests/multi_project', __dir__)
|
278
299
|
expect(@generator.projects(path)).to eq %w[SamplePipeline1 SamplePipeline2 SamplePipeline3]
|
279
300
|
end
|
280
301
|
end
|
@@ -292,9 +313,19 @@ describe JenkinsPipelineBuilder::Generator do
|
|
292
313
|
File.delete(file_path) if File.exist?(file_path)
|
293
314
|
end
|
294
315
|
end
|
316
|
+
|
295
317
|
it 'generates xml and saves to disk without sending jobs to the server' do
|
318
|
+
tar_path = File.join(__dir__, 'fixtures/generator_tests/template_pipeline_nested/jobs.tar.gz')
|
319
|
+
parsed_url = URI.parse('https://www.test.com')
|
320
|
+
file_contents = Zlib::GzipReader.new(File.open(tar_path)).read
|
321
|
+
file_object = double
|
322
|
+
allow(URI).to receive(:parse).and_return(parsed_url)
|
323
|
+
allow(parsed_url).to receive(:open).and_yield('A String')
|
324
|
+
allow(Zlib::GzipReader).to receive(:new).and_return(file_object)
|
325
|
+
allow(file_object).to receive(:read).and_return(file_contents)
|
326
|
+
|
296
327
|
job_name = 'TemplatePipeline'
|
297
|
-
path = File.expand_path('
|
328
|
+
path = File.expand_path('fixtures/generator_tests/template_pipeline', __dir__)
|
298
329
|
errors = @generator.file(path, job_name)
|
299
330
|
expect(errors).to be_empty
|
300
331
|
expect(File.exist?("out/xml/#{job_name}-10.xml")).to be true
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('spec_helper', __dir__)
|
2
2
|
|
3
3
|
describe JenkinsPipelineBuilder::JobCollection do
|
4
4
|
before :all do
|
@@ -21,7 +21,7 @@ describe JenkinsPipelineBuilder::JobCollection do
|
|
21
21
|
|
22
22
|
context '#load_from_path' do
|
23
23
|
before :all do
|
24
|
-
path = File.expand_path('
|
24
|
+
path = File.expand_path('fixtures/job_collection', __dir__)
|
25
25
|
described_class.new.load_from_path path
|
26
26
|
end
|
27
27
|
|
@@ -6,7 +6,7 @@ require 'simplecov-rcov'
|
|
6
6
|
require 'webmock/rspec'
|
7
7
|
require 'equivalent-xml'
|
8
8
|
|
9
|
-
require File.expand_path('
|
9
|
+
require File.expand_path('../../../lib/jenkins_pipeline_builder', __dir__)
|
10
10
|
|
11
11
|
RSpec::Matchers.define :have_min_version do |version|
|
12
12
|
match do |base|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('spec_helper', __dir__)
|
2
2
|
|
3
3
|
describe JenkinsPipelineBuilder::View do
|
4
4
|
before(:all) do
|
@@ -12,7 +12,7 @@ describe JenkinsPipelineBuilder::View do
|
|
12
12
|
generator = JenkinsPipelineBuilder.generator
|
13
13
|
@view = JenkinsPipelineBuilder::View.new(generator)
|
14
14
|
end
|
15
|
-
let(:path) { File.expand_path('
|
15
|
+
let(:path) { File.expand_path('fixtures/view_test', __dir__) }
|
16
16
|
let(:view) { { name: 'view', parent_view: 'ParentView', type: 'categorizedView', description: 'ViewTest', regex: 'ViewTest.*', groupingRules: [{ groupRegex: 'ViewTest-1.*', namingRule: '1. Commit Stage' }] } }
|
17
17
|
|
18
18
|
describe '#generate' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenkins_pipeline_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Moochnick
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -394,7 +394,6 @@ files:
|
|
394
394
|
- lib/jenkins_pipeline_builder/utils.rb
|
395
395
|
- lib/jenkins_pipeline_builder/version.rb
|
396
396
|
- lib/jenkins_pipeline_builder/view.rb
|
397
|
-
- out/.keep
|
398
397
|
- pipeline/Jenkins-Pipeline-Builder.yaml
|
399
398
|
- pipeline/project.yaml
|
400
399
|
- spec/lib/jenkins_pipeline_builder/cli/helper_spec.rb
|
@@ -485,7 +484,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
485
484
|
version: '0'
|
486
485
|
requirements: []
|
487
486
|
rubyforge_project:
|
488
|
-
rubygems_version: 2.7.
|
487
|
+
rubygems_version: 2.7.7
|
489
488
|
signing_key:
|
490
489
|
specification_version: 4
|
491
490
|
summary: This gem is will boostrap your Jenkins pipelines
|