jenkins_pipeline_builder 0.10.11 → 0.10.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzhiNTViYTRjNzBmMGYwZDcwOTdjMjNhOWM4ZjlmYjY0MmY3NGI5NA==
4
+ ZTM5YTI4ZDgwN2M1YjZjNzQ3MWY5NzliM2U4MTA4NmQ3MjQ5N2Y4NA==
5
5
  data.tar.gz: !binary |-
6
- MjE0NGFjMzMxMjRmZGZlZjNkYTdmNzg2YWU5NTFmMDQ5MzcxMmRlMA==
6
+ MWFhY2QyYzc5MWQyOGM5MmE3YTM2MzhhNGY5ZWUxODdmMTQ0YjFiMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjIwN2M5MTIxYzc1YmQ4NDY5MjU0NjhlZGEzMTEzZmU1MzZkOGE4Y2QyNGY3
10
- MGQ5OTE5ZTg0ZTAxZmEyZjZmMTlkMGMzNDA0ZTQ1NzkyM2ZmMjk5MmRmNzI4
11
- MmZkYTE0YTFmZjRmMzgwNzJhYjcwNDlmN2U4OGFmODhiODk1YmE=
9
+ NThjODRiYzA3ZDY1NDJmY2NjZWJjOTY3MTY0YmJmMTkyZTllODc4YTc0YmI5
10
+ MDhhODgyYWM3ZjdlZTQwZmFhY2U4YWJkZTQ4MjYwNzg4YmYyZWQ4ZGZmNjJh
11
+ NTMzMzJlOTBlOGY4MGViZjFiMWU0Yzk3NjYyNjI2MWQ2YzM0MjI=
12
12
  data.tar.gz: !binary |-
13
- YzM3NGQ0OTgxNDA5OTAzNjFkNjJhZTVmYWU1MDg4Mzk2NDNhN2Y2NWEyYjU2
14
- ZjY0NjhmMjVkNmNkMjU3NmYyNWI4MGRiZTczMDg4ZDc5NDcwYjhlMWNmMzcw
15
- Y2M3Y2VmMjZmOWU3YjNmOGUxMmVmNjk3MmEwZjBhODk3Y2NjOTU=
13
+ NzhmYjZkNGRlMTVmYTBlNDBkNDRkMjE5YzMzZGIwYzZlMjRkMjI2YjkwYzlm
14
+ ODY2NGUwMDlkODVlNjcyZmNjNzIzMDk3NWJkMTJkMDdlMGFmZmE1NDE1NGNl
15
+ NzhkMjRmNmM4MDBkOTIzNTFhMDFkYmViNDc0MzQyNzcxYzNhNGY=
data/.rubocop.yml CHANGED
@@ -7,7 +7,7 @@ Metrics/PerceivedComplexity:
7
7
  Metrics/MethodLength:
8
8
  Max: 27
9
9
  Metrics/ClassLength:
10
- Max: 525
10
+ Max: 350
11
11
 
12
12
  #######
13
13
  # Finalized settings
@@ -30,15 +30,36 @@ require 'jenkins_pipeline_builder/module_registry'
30
30
  require 'jenkins_pipeline_builder/pull_request_generator'
31
31
  require 'jenkins_pipeline_builder/pull_request'
32
32
  require 'jenkins_pipeline_builder/view'
33
+ require 'jenkins_pipeline_builder/job_collection'
34
+ require 'jenkins_pipeline_builder/job'
35
+ require 'jenkins_pipeline_builder/remote_dependencies'
33
36
  require 'jenkins_pipeline_builder/generator'
34
37
 
35
38
  module JenkinsPipelineBuilder
36
39
  class << self
37
- attr_reader :client, :credentials
40
+ attr_reader :client, :credentials, :debug, :file_mode
38
41
  def generator
39
42
  @_generator ||= Generator.new
40
43
  end
41
44
 
45
+ def file_mode!
46
+ @file_mode = true
47
+ end
48
+
49
+ def normal_mode!
50
+ @file_mode = false
51
+ end
52
+
53
+ def debug!
54
+ @debug = true
55
+ @client.logger.level = Logger::DEBUG
56
+ end
57
+
58
+ def no_debug!
59
+ @debug = false
60
+ @client.logger.level = Logger::INFO
61
+ end
62
+
42
63
  def credentials=(creds)
43
64
  @credentials = creds
44
65
  @client = JenkinsApi::Client.new(credentials)
@@ -57,6 +78,8 @@ module JenkinsPipelineBuilder
57
78
  end
58
79
  JenkinsPipelineBuilder.generator
59
80
  require 'jenkins_pipeline_builder/extensions'
81
+ require 'jenkins_pipeline_builder/extension_dsl'
82
+ require 'jenkins_pipeline_builder/extension_set'
60
83
  require 'jenkins_pipeline_builder/extensions/builders'
61
84
  require 'jenkins_pipeline_builder/extensions/job_attributes'
62
85
  require 'jenkins_pipeline_builder/extensions/wrappers'
@@ -40,31 +40,35 @@ module JenkinsPipelineBuilder
40
40
  # @return [JenkinsPipelineBuilder::Generator] A new Client object
41
41
  #
42
42
  def self.setup(options)
43
+ creds = process_creds options
44
+
45
+ JenkinsPipelineBuilder.credentials = creds
46
+ generator = JenkinsPipelineBuilder.generator
47
+ JenkinsPipelineBuilder.debug! if options[:debug]
48
+ generator
49
+ end
50
+
51
+ def self.process_creds(options)
43
52
  if options[:username] && options[:server] && (options[:password] || options[:password_base64])
44
- creds = process_cli_creds(options)
53
+ return process_cli_creds(options)
45
54
  elsif options[:creds_file]
46
55
  if options[:creds_file].end_with? 'json'
47
- creds = JSON.parse(IO.read(File.expand_path(options[:creds_file])))
56
+ return JSON.parse(IO.read(File.expand_path(options[:creds_file])))
48
57
  else
49
- creds = YAML.load_file(File.expand_path(options[:creds_file]))
58
+ return YAML.load_file(File.expand_path(options[:creds_file]))
50
59
  end
51
60
  elsif File.exist?("#{ENV['HOME']}/.jenkins_api_client/login.yml")
52
- creds = YAML.load_file(
61
+ return YAML.load_file(
53
62
  File.expand_path("#{ENV['HOME']}/.jenkins_api_client/login.yml", __FILE__)
54
63
  )
55
64
  elsif options[:debug]
56
- creds = { username: :foo, password: :bar, server_ip: :baz }
65
+ return { username: :foo, password: :bar, server_ip: :baz }
57
66
  else
58
67
  msg = 'Credentials are not set. Please pass them as parameters or'
59
68
  msg << ' set them in the default credentials file'
60
69
  $stderr.puts msg
61
70
  exit 1
62
71
  end
63
-
64
- JenkinsPipelineBuilder.credentials = creds
65
- generator = JenkinsPipelineBuilder.generator
66
- generator.debug = options[:debug]
67
- generator
68
72
  end
69
73
 
70
74
  def self.process_cli_creds(options)
@@ -0,0 +1,21 @@
1
+ JenkinsPipelineBuilder.registry.entries.each do |type, path|
2
+ singular_type = type.to_s.singularize
3
+ define_method singular_type do |&block|
4
+ set = JenkinsPipelineBuilder::ExtensionSet.new singular_type, path, &block
5
+ return false unless set.valid?
6
+
7
+ JenkinsPipelineBuilder.registry.register([:job, type], set)
8
+ versions = set.extensions.map(&:min_version)
9
+ puts "Successfully registered #{set.name} for versions #{versions}" if set.announced
10
+ true
11
+ end
12
+ end
13
+
14
+ def job_attribute(&block)
15
+ set = JenkinsPipelineBuilder::ExtensionSet.new :job_attribute, &block
16
+ return false unless set.valid?
17
+
18
+ JenkinsPipelineBuilder.registry.register([:job], set)
19
+ versions = set.extensions.map(&:min_version)
20
+ puts "Successfully registered #{set.name} for versions #{versions}" if set.announced
21
+ end
@@ -0,0 +1,174 @@
1
+ module JenkinsPipelineBuilder
2
+ class ExtensionSet
3
+ SET_METHODS = [
4
+ :name,
5
+ :plugin_id,
6
+ :jenkins_name,
7
+ :description,
8
+ :announced,
9
+ :type
10
+ ]
11
+ SET_METHODS.each do |method_name|
12
+ define_method method_name do |value = nil|
13
+ return settings[method_name] if value.nil?
14
+ settings[method_name] = value
15
+ end
16
+ end
17
+
18
+ attr_accessor :blocks, :extensions, :settings
19
+
20
+ def initialize(type, path = nil, &block)
21
+ @blocks = {}
22
+ @settings = {}
23
+ @extensions = []
24
+
25
+ instance_eval(&block)
26
+
27
+ blocks.each do |version, settings|
28
+ add_extension type, version, settings, path
29
+ end
30
+ end
31
+
32
+ def installed_version=(version)
33
+ version = version.match(/\d+\.\d+/)
34
+ @version = Gem::Version.new version
35
+ end
36
+
37
+ def add_extension(type, version, settings, path = nil)
38
+ ext = JenkinsPipelineBuilder::Extension.new
39
+ ext.min_version version
40
+ ext.type type
41
+ self.settings.merge(settings).each do |key, value|
42
+ ext.send key, value
43
+ end
44
+
45
+ ext.path path unless ext.path
46
+ extensions << ext
47
+ end
48
+
49
+ def installed_version
50
+ return @version if @version
51
+ reg = JenkinsPipelineBuilder.registry
52
+ version = reg.versions[settings[:plugin_id]]
53
+ fail "Plugin #{settings[:name]} is not installed (plugin_id: #{settings[:plugin_id]})" if version.nil?
54
+ self.installed_version = version
55
+ @version
56
+ end
57
+
58
+ def extension
59
+ # TODO: Support multiple xml sections for the native to jenkins plugins
60
+ return extensions.first if settings[:plugin_id] == 'builtin'
61
+
62
+ extension = versions[highest_allowed_version]
63
+
64
+ unless extension
65
+ fail "Can't find version of #{name} lte #{installed_version}, available versions: #{versions.keys.map(&:to_s)}"
66
+ end
67
+ extension
68
+ end
69
+
70
+ def merge(other_set)
71
+ mismatch = []
72
+ SET_METHODS.each do |method_name|
73
+ val1 = settings[method_name]
74
+ val2 = other_set.settings[method_name]
75
+ mismatch << "The values for #{method_name} do not match '#{val1}' : '#{val2}'" unless val1 == val2
76
+ end
77
+ mismatch.each do |error|
78
+ puts error
79
+ end
80
+ fail 'Values did not match, cannot merge extension sets' if mismatch.any?
81
+
82
+ blocks.merge other_set.blocks
83
+ end
84
+
85
+ def parameters(params)
86
+ version = @min_version || '0'
87
+
88
+ blocks[version] = {} unless blocks[version]
89
+ blocks[version][:parameters] = params
90
+ end
91
+
92
+ def xml(path: false, version: '0', &block)
93
+ if @min_version
94
+ version = @min_version
95
+ elsif version != '0'
96
+ deprecation_warning(settings[:name], 'xml')
97
+ end
98
+ unless block
99
+ fail "no block found for version #{version}" unless blocks.key version
100
+ return blocks[version][:block]
101
+ end
102
+ store_xml version, block, path
103
+ end
104
+
105
+ def version(ver, &block)
106
+ @min_version = ver
107
+ yield block
108
+ end
109
+
110
+ [:after, :before].each do |method_name|
111
+ define_method method_name do |version: '0', &block|
112
+ if @min_version
113
+ version = @min_version
114
+ elsif version != '0'
115
+ deprecation_warning(settings[:name], method_name)
116
+ end
117
+
118
+ return instance_variable_get(method_name) unless block
119
+ blocks[version] = {} unless blocks[version]
120
+ blocks[version][method_name] = block
121
+ end
122
+ end
123
+
124
+ def valid?
125
+ valid = errors.empty?
126
+ unless valid
127
+ name ||= 'A plugin with no name provided'
128
+ puts "Encountered errors while registering #{name}"
129
+ puts errors.map { |k, v| "#{k}: #{v}" }.join(', ')
130
+ end
131
+ valid
132
+ end
133
+
134
+ def errors
135
+ errors = {}
136
+ errors['ExtensionSet'] = 'no extensions successfully registered' if extensions.empty?
137
+ extensions.each do |ext|
138
+ ver = ext.min_version || 'unknown'
139
+ errors["#{ext.name} version #{ver}"] = ext.errors unless ext.valid?
140
+ end
141
+ errors
142
+ end
143
+
144
+ private
145
+
146
+ def highest_allowed_version
147
+ ordered_version_list.each do |version|
148
+ return version if version <= installed_version
149
+ end
150
+ end
151
+
152
+ def store_xml(version, block, path)
153
+ if blocks[version]
154
+ blocks[version].merge!(xml: block, path: path)
155
+ else
156
+ blocks[version] = { xml: block, path: path }
157
+ end
158
+ end
159
+
160
+ def versions
161
+ @versions ||= extensions.each_with_object({}) do |ext, hash|
162
+ hash[Gem::Version.new(ext.min_version)] = ext
163
+ end
164
+ end
165
+
166
+ def ordered_version_list
167
+ versions.keys.sort.reverse
168
+ end
169
+
170
+ def deprecation_warning(name, block)
171
+ puts "WARNING: #{name} set the version in the #{block} block, this is deprecated. Please use a version block."
172
+ end
173
+ end
174
+ end
@@ -42,181 +42,6 @@ def job_attribute(&block)
42
42
  puts "Successfully registered #{set.name} for versions #{versions}" if set.announced
43
43
  end
44
44
 
45
- module JenkinsPipelineBuilder
46
- class ExtensionSet
47
- SET_METHODS = [
48
- :name,
49
- :plugin_id,
50
- :jenkins_name,
51
- :description,
52
- :announced,
53
- :type
54
- ]
55
- SET_METHODS.each do |method_name|
56
- define_method method_name do |value = nil|
57
- return settings[method_name] if value.nil?
58
- settings[method_name] = value
59
- end
60
- end
61
-
62
- attr_accessor :blocks, :extensions, :settings
63
-
64
- def initialize(type, path = nil, &block)
65
- @blocks = {}
66
- @settings = {}
67
- @extensions = []
68
-
69
- instance_eval(&block)
70
-
71
- blocks.each do |version, settings|
72
- add_extension type, version, settings, path
73
- end
74
- end
75
-
76
- def installed_version=(version)
77
- version = version.match(/\d+\.\d+/)
78
- @version = Gem::Version.new version
79
- end
80
-
81
- def add_extension(type, version, settings, path = nil)
82
- ext = JenkinsPipelineBuilder::Extension.new
83
- ext.min_version version
84
- ext.type type
85
- self.settings.merge(settings).each do |key, value|
86
- ext.send key, value
87
- end
88
-
89
- ext.path path unless ext.path
90
- extensions << ext
91
- end
92
-
93
- def installed_version
94
- return @version if @version
95
- reg = JenkinsPipelineBuilder.registry
96
- version = reg.versions[settings[:plugin_id]]
97
- fail "Plugin #{settings[:name]} is not installed (plugin_id: #{settings[:plugin_id]})" if version.nil?
98
- self.installed_version = version
99
- @version
100
- end
101
-
102
- def extension
103
- # TODO: Support multiple xml sections for the native to jenkins plugins
104
- return extensions.first if settings[:plugin_id] == 'builtin'
105
-
106
- extension = versions[highest_allowed_version]
107
-
108
- unless extension
109
- fail "Can't find version of #{name} lte #{installed_version}, available versions: #{versions.keys.map(&:to_s)}"
110
- end
111
- extension
112
- end
113
-
114
- def merge(other_set)
115
- mismatch = []
116
- SET_METHODS.each do |method_name|
117
- val1 = settings[method_name]
118
- val2 = other_set.settings[method_name]
119
- mismatch << "The values for #{method_name} do not match '#{val1}' : '#{val2}'" unless val1 == val2
120
- end
121
- mismatch.each do |error|
122
- puts error
123
- end
124
- fail 'Values did not match, cannot merge extension sets' if mismatch.any?
125
-
126
- blocks.merge other_set.blocks
127
- end
128
-
129
- def parameters(params)
130
- version = @min_version || '0'
131
-
132
- blocks[version] = {} unless blocks[version]
133
- blocks[version][:parameters] = params
134
- end
135
-
136
- def xml(path: false, version: '0', &block)
137
- if @min_version
138
- version = @min_version
139
- elsif version != '0'
140
- deprecation_warning(settings[:name], 'xml')
141
- end
142
- unless block
143
- fail "no block found for version #{version}" unless blocks.key version
144
- return blocks[version][:block]
145
- end
146
- store_xml version, block, path
147
- end
148
-
149
- def version(ver, &block)
150
- @min_version = ver
151
- yield block
152
- end
153
-
154
- [:after, :before].each do |method_name|
155
- define_method method_name do |version: '0', &block|
156
- if @min_version
157
- version = @min_version
158
- elsif version != '0'
159
- deprecation_warning(settings[:name], method_name)
160
- end
161
-
162
- return instance_variable_get(method_name) unless block
163
- blocks[version] = {} unless blocks[version]
164
- blocks[version][method_name] = block
165
- end
166
- end
167
-
168
- def valid?
169
- valid = errors.empty?
170
- unless valid
171
- name ||= 'A plugin with no name provided'
172
- puts "Encountered errors while registering #{name}"
173
- puts errors.map { |k, v| "#{k}: #{v}" }.join(', ')
174
- end
175
- valid
176
- end
177
-
178
- def errors
179
- errors = {}
180
- errors['ExtensionSet'] = 'no extensions successfully registered' if extensions.empty?
181
- extensions.each do |ext|
182
- ver = ext.min_version || 'unknown'
183
- errors["#{ext.name} version #{ver}"] = ext.errors unless ext.valid?
184
- end
185
- errors
186
- end
187
-
188
- private
189
-
190
- def highest_allowed_version
191
- ordered_version_list.each do |version|
192
- return version if version <= installed_version
193
- end
194
- end
195
-
196
- def store_xml(version, block, path)
197
- if blocks[version]
198
- blocks[version].merge!(xml: block, path: path)
199
- else
200
- blocks[version] = { xml: block, path: path }
201
- end
202
- end
203
-
204
- def versions
205
- @versions ||= extensions.each_with_object({}) do |ext, hash|
206
- hash[Gem::Version.new(ext.min_version)] = ext
207
- end
208
- end
209
-
210
- def ordered_version_list
211
- versions.keys.sort.reverse
212
- end
213
-
214
- def deprecation_warning(name, block)
215
- puts "WARNING: #{name} set the version in the #{block} block, this is deprecated. Please use a version block."
216
- end
217
- end
218
- end
219
-
220
45
  module JenkinsPipelineBuilder
221
46
  class Extension
222
47
  EXT_METHODS = {