cicd-builder 0.9.57 → 0.9.58

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cd62a29105d756c322af200c6db09a82e48d21f
4
- data.tar.gz: 3991bcdb072641afc910612c6693e7b7185ccc97
3
+ metadata.gz: 522beabff1900c244ed53801399e11be374bafcc
4
+ data.tar.gz: 146221813e4293e4b728d3811f08dd1714313b81
5
5
  SHA512:
6
- metadata.gz: 4c6c6a0842aa204d488c99da2b65e77838331d30360c3c6afff34d81f285253f622c79945fe854e834643aa49869e91e075316e9ae8f538d32fa6d9a9130bad6
7
- data.tar.gz: 88452616373f9c9fd1ef51a339a7f7670957a4d894cd1a530b1b0ffd946e5ae5ff324aa1a3538b809be225457f2c72e504866f875a8d04681308224b51800559
6
+ metadata.gz: 172c4e3d2b22f88241e0571e9058771cfe1fa76c9de9fa35efacb86a22afe7318c4232c4d17dbfc4072191a61ed47063a9863f65db30832c6c7acb31b0b0a130
7
+ data.tar.gz: 9dc95e9d79a69d67695e2aa958c6accdc6321487352a1babbc1f64f2e3c062f28550d9cd87241c9141b5bdeaa02987fa4bd7ad8c4f6c4f3d06c1307516011459
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cicd-builder (0.9.57)
4
+ cicd-builder (0.9.58)
5
5
  artifactory (>= 2.2.1, < 2.3)
6
6
  awesome_print (>= 1.6, < 2.0)
7
7
  aws-sdk (>= 2.0, < 2.1)
@@ -222,6 +222,12 @@ module CiCd
222
222
  ret
223
223
  end
224
224
 
225
+ # ---------------------------------------------------------------------------------------------------------------
226
+ def cleanupAfterUpload()
227
+ @logger.info CLASS+'::'+__method__.to_s
228
+ @logger.debug = %(Prior to VERSION 0.9.58 there was no #{__method__.to_s} action)
229
+ end
230
+
225
231
  # ---------------------------------------------------------------------------------------------------------------
226
232
  def createMetaData()
227
233
  @logger.info CLASS+'::'+__method__.to_s
@@ -65,8 +65,10 @@ module CiCd
65
65
  @vars[:build_store] = "#{ENV['BUILD_STORE']}"
66
66
  end
67
67
 
68
- if ENV.has_key?('BRANCH')
69
- @vars[:branch] = "#{ENV['BRANCH'].gsub(%r'\/','.')}"
68
+ if ENV.has_key?('GIT_BRANCH')
69
+ @vars[:branch] = "#{ENV['GIT_BRANCH'].gsub(%r'^(refs/[^/]?|origin)/','').gsub(%r'\/','.')}"
70
+ elsif ENV.has_key?('BRANCH')
71
+ @vars[:branch] = "#{ENV['BRANCH'].gsub(%r'\/','.')}"
70
72
  end
71
73
 
72
74
  if ENV.has_key?('VARIANT')
@@ -80,7 +82,7 @@ module CiCd
80
82
  if ENV.has_key?('ACTIONS')
81
83
  @vars[:actions] = ENV['ACTIONS'].split(%r'[, \t]+')
82
84
  else
83
- @vars[:actions] = %w(prepareBuild makeBuild saveBuild uploadBuildArtifacts)
85
+ @vars[:actions] = %w(prepareBuild makeBuild saveBuild uploadBuildArtifacts cleanupAfterUpload)
84
86
  end
85
87
 
86
88
  if ENV.has_key?('TREE')
@@ -59,6 +59,8 @@ module CiCd
59
59
  REPO_BAD_BRANCH = i+=1
60
60
  REPO_NO_BUILD = i+=1
61
61
 
62
+ NO_ACCOUNTS = i+=1
63
+
62
64
  PRUNE_TOO_OLD = REPO_TOO_OLD
63
65
 
64
66
  require 'awesome_print'
@@ -147,7 +147,7 @@ module CiCd
147
147
  manifest[:env][k.to_s] = v
148
148
  end
149
149
  }
150
- JSON.pretty_generate( manifest, { indent: "\t", space: ' '})
150
+ JSON.pretty_generate( manifest.to_hash, { indent: "\t", space: ' '})
151
151
  end
152
152
 
153
153
  # ---------------------------------------------------------------------------------------------------------------
@@ -168,6 +168,7 @@ module CiCd
168
168
  }
169
169
  @vars[:return_code]
170
170
  end
171
+ alias_method :cicd_uploadToRepo, :uploadToRepo
171
172
 
172
173
  def get_artifact_file_name_ext(data)
173
174
  file_name = File.basename(data[:file])
@@ -193,16 +194,17 @@ module CiCd
193
194
  artifact_version = args[:artifact_version]
194
195
  file_ext = args[:file_ext]
195
196
  file_name = args[:file_name]
197
+ make_copy = (args[:copy].nil? or args[:copy])
196
198
 
197
199
  artifact_name = getArtifactName(data[:name], file_name, artifact_version, file_ext) # artifact_path = "#{artifactory_org_path()}/#{data[:name]}/#{data[:version]}-#{@vars[:variant]}/#{artifact_name}"
198
200
  artifact_path = getArtifactPath(artifact_module, artifact_version, artifact_name)
199
- objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
201
+ objects = maybeArtifactoryObject(artifact_module, artifact_version, false, args[:repo])
200
202
  upload = false
201
203
  matched = []
202
204
  if objects.nil? or objects.size == 0
203
205
  upload = true
204
206
  else
205
- @logger.info "#{artifactory_endpoint()}/#{artifactory_repo()}/#{artifact_path} exists - #{objects.size} results"
207
+ @logger.info "#{artifactory_endpoint()}/#{args[:repo] || artifactory_repo()}/#{artifact_path} exists - #{objects.size} results"
206
208
  @logger.info "\t#{objects.map{|o| o.attributes[:uri]}.join("\n\t")}"
207
209
  matched = matchArtifactoryObjects(artifact_path, data, objects)
208
210
  upload ||= (matched.size == 0)
@@ -213,7 +215,7 @@ module CiCd
213
215
  properties_matrix["product.#{k}"] = v
214
216
  end
215
217
  data[:properties] = properties_matrix.merge(@properties_matrix)
216
- objects = uploadArtifact(artifact_module, artifact_version, artifact_path, data)
218
+ objects = uploadArtifact(artifact_module, artifact_version, artifact_path, data, args[:repo])
217
219
  matched = matchArtifactoryObjects(artifact_path, data, objects)
218
220
  else
219
221
  @logger.info "Keep existing #{matched.map{|o| o.attributes[:uri]}.join("\t")}"
@@ -228,16 +230,16 @@ module CiCd
228
230
  end
229
231
  end
230
232
  @vars[:return_code] = Errors::ARTIFACT_NOT_UPLOADED unless matched.size > 0
231
- if @vars[:return_code] == 0
233
+ if @vars[:return_code] == 0 and make_copy
232
234
  artifact_version += "-#{data[:build] || @vars[:build_num]}"
233
235
  artifact_name = getArtifactName(data[:name], file_name, artifact_version, file_ext, )
234
236
  artifact_path = getArtifactPath(artifact_module, artifact_version, artifact_name)
235
- copies = maybeArtifactoryObject(artifact_module, artifact_version, false)
237
+ copies = maybeArtifactoryObject(artifact_module, artifact_version, false, args[:repo])
236
238
  matched = matchArtifactoryObjects(artifact_path, data, copies)
237
239
  upload = (matched.size == 0)
238
240
  if upload
239
241
  objects.each do |artifact|
240
- copied = copyArtifact(artifact_module, artifact_version, artifact_path, artifact)
242
+ copied = copyArtifact(artifact_module, artifact_version, artifact_path, artifact, args[:repo])
241
243
  unless copied.size > 0
242
244
  @vars[:return_code] = Errors::ARTIFACT_NOT_COPIED
243
245
  break
@@ -255,6 +257,7 @@ module CiCd
255
257
 
256
258
  @vars[:return_code]
257
259
  end
260
+ alias_method :cicd_maybeUploadArtifactoryObject, :maybeUploadArtifactoryObject
258
261
 
259
262
  def matchArtifactoryObjects(artifact_path, data, objects)
260
263
  # matched = false
@@ -277,30 +280,13 @@ module CiCd
277
280
  end
278
281
 
279
282
  # ---------------------------------------------------------------------------------------------------------------
280
- def maybeArtifactoryObject(artifact_name,artifact_version,wide=true)
283
+ def maybeArtifactoryObject(artifact_name,artifact_version,wide=true,repo=nil)
281
284
  begin
282
285
  # Get a list of matching artifacts in this repository
283
- @logger.info "Artifactory gavc_search g=#{artifactory_org_path()},a=#{artifact_name},v=#{artifact_version},r=#{artifactory_repo()}"
286
+ @logger.info "Artifactory gavc_search g=#{artifactory_org_path()},a=#{artifact_name},v=#{artifact_version},r=#{repo || artifactory_repo()}"
284
287
  @arti_search_result = []
285
- # results = ::Parallel.map([:search,:progress], preserve_results: true, in_threads: 2) { |task|
286
- # if task == :search
287
- # @logger.debug 'searching ... '
288
- # @arti_search_result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [artifactory_repo()])
289
- # @logger.debug 'searching complete!'
290
- # raise ::Parallel::Kill
291
- # # raise ::Parallel::Break # -> stops after all current items are finished
292
- # else
293
- # progressbar = ::ProgressBar.create(:title => 'artifact_gavc_search', progress_mark: '=', length: 30, remainder_mark: '.')
294
- # 30.times { |i|
295
- # @logger.debug i
296
- # sleep 1
297
- # progressbar.increment
298
- # }
299
- # raise ::Parallel::Kill
300
- # end
301
- # }
302
288
  monitor(30, 'artifact_gavc_search'){
303
- @arti_search_result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [artifactory_repo()])
289
+ @arti_search_result = @client.artifact_gavc_search(group: artifactory_org_path(), name: artifact_name, version: "#{artifact_version}", repos: [repo || artifactory_repo()])
304
290
  }
305
291
  # noinspection RubyScope
306
292
  if @arti_search_result.size > 0
@@ -317,6 +303,26 @@ module CiCd
317
303
  end
318
304
  end
319
305
 
306
+ # ---------------------------------------------------------------------------------------------------------------
307
+ def latestArtifactoryVersion(artifact_name, repo=nil)
308
+ begin
309
+ # Get a list of matching artifacts in this repository
310
+ @logger.info "Artifactory latest_version g=#{artifactory_org_path()},a=#{artifact_name},r=#{repo || artifactory_repo()}"
311
+ @arti_search_result = []
312
+ monitor(30, 'artifact_latest_version'){
313
+ @arti_search_result = ::Artifactory::Resource::Artifact.latest_version(client: @client, group: artifactory_org_path(), name: artifact_name, repos: [repo || artifactory_repo()])
314
+ }
315
+ # noinspection RubyScope
316
+ if @arti_search_result.size > 0
317
+ @logger.info "\tresult: #{@arti_search_result}"
318
+ end
319
+ @arti_search_result
320
+ rescue Exception => e
321
+ @logger.error "Artifactory error: #{e.class.name} #{e.message}"
322
+ raise e
323
+ end
324
+ end
325
+
320
326
  def monitor(limit,title='Progress')
321
327
  raise 'Must have a block' unless block_given?
322
328
  thread = Thread.new(){
@@ -337,7 +343,7 @@ module CiCd
337
343
  thread.kill if thread.alive? or thread.stop?
338
344
  end
339
345
 
340
- def uploadArtifact(artifact_module, artifact_version, artifact_path, data)
346
+ def uploadArtifact(artifact_module, artifact_version, artifact_path, data, repo=nil)
341
347
  data[:size] = File.size(data[:file])
342
348
  artifact = ::Artifactory::Resource::Artifact.new(local_path: data[:file], client: @client)
343
349
  # noinspection RubyStringKeysInHashInspection
@@ -348,14 +354,14 @@ module CiCd
348
354
  artifact.size = data[:size]
349
355
  @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start upload #{artifact_path} = #{data[:size]} bytes"
350
356
  monitor(30, 'upload') {
351
- @arti_upload_result = artifact.upload(artifactory_repo(), "#{artifact_path}", data[:properties] || {})
357
+ @arti_upload_result = artifact.upload(repo || artifactory_repo(), "#{artifact_path}", data[:properties] || {})
352
358
  }
353
359
  @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Uploaded: #{@arti_upload_result.attributes.select { |k, _| k != :client }.ai}"
354
360
  3.times{
355
361
  @arti_upload_checksum = false
356
362
  monitor(30, 'upload_checksum') {
357
363
  begin
358
- artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :sha1, data[:sha1])
364
+ artifact.upload_checksum(repo || artifactory_repo(), "#{artifact_path}", :sha1, data[:sha1])
359
365
  @arti_upload_checksum = true
360
366
  rescue Exception => e
361
367
  @logger.fatal "Failed to upload #{artifact_path}: #{e.class.name} #{e.message}"
@@ -369,7 +375,7 @@ module CiCd
369
375
  @arti_upload_checksum = false
370
376
  monitor(30, 'upload_checksum') {
371
377
  begin
372
- artifact.upload_checksum(artifactory_repo(), "#{artifact_path}", :md5, data[:md5])
378
+ artifact.upload_checksum(repo || artifactory_repo(), "#{artifact_path}", :md5, data[:md5])
373
379
  @arti_upload_checksum = true
374
380
  rescue Exception => e
375
381
  @logger.fatal "Failed to upload #{artifact_path}: #{e.class.name} #{e.message}"
@@ -382,7 +388,7 @@ module CiCd
382
388
  attempt = 0
383
389
  objects = []
384
390
  while attempt < 3
385
- objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
391
+ objects = maybeArtifactoryObject(artifact_module, artifact_version, false, repo)
386
392
  break if objects.size > 0
387
393
  sleep 2
388
394
  attempt += 1
@@ -391,9 +397,9 @@ module CiCd
391
397
  objects
392
398
  end
393
399
 
394
- def copyArtifact(artifact_module, artifact_version, artifact_path, artifact)
400
+ def copyArtifact(artifact_module, artifact_version, artifact_path, artifact, repo=nil)
395
401
  begin
396
- if artifact.attributes[:uri].eql?(File.join(artifactory_endpoint, artifactory_repo, artifact_path))
402
+ if artifact.attributes[:uri].eql?(File.join(artifactory_endpoint, repo || artifactory_repo, artifact_path))
397
403
  @logger.info "Not copying (identical artifact): #{artifact_path}"
398
404
  else
399
405
  @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Start copy #{artifact_path} = #{artifact.attributes[:size]} bytes"
@@ -401,7 +407,7 @@ module CiCd
401
407
  3.times{
402
408
  copied = false
403
409
  monitor(30){
404
- result = artifact.copy("#{artifactory_repo()}/#{artifact_path}")
410
+ result = artifact.copy("#{repo || artifactory_repo()}/#{artifact_path}")
405
411
  @logger.info "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}] Copied: #{result.ai}"
406
412
  copied = true
407
413
  }
@@ -409,10 +415,10 @@ module CiCd
409
415
  }
410
416
  raise "Failed to copy #{artifact_path}" unless copied
411
417
  end
412
- objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
418
+ objects = maybeArtifactoryObject(artifact_module, artifact_version, false, repo)
413
419
  unless objects.size > 0
414
420
  sleep 10
415
- objects = maybeArtifactoryObject(artifact_module, artifact_version, false)
421
+ objects = maybeArtifactoryObject(artifact_module, artifact_version, false, repo)
416
422
  raise "Failed to copy '#{artifact_path}'" unless objects.size > 0
417
423
  end
418
424
  objects
@@ -452,7 +458,7 @@ module CiCd
452
458
  # end
453
459
  @vars[:return_code]
454
460
  rescue => e
455
- @logger.error "#{e.class.name} #{e.message}"
461
+ @logger.error "#{e.class.name} #{e.message}\n#{e.backtrace.ai}"
456
462
  @vars[:return_code] = Errors::ARTIFACT_UPLOAD_EXCEPTION
457
463
  raise e
458
464
  end
@@ -4,7 +4,7 @@ module CiCd
4
4
  # file = File.expand_path("#{File.dirname(__FILE__)}/../../../VERSION")
5
5
  # lines = File.readlines(file)
6
6
  # version = lines[0]
7
- version = '0.9.57'
7
+ version = '0.9.58'
8
8
  VERSION = version unless const_defined?('VERSION')
9
9
  major, minor, tiny = VERSION.split('.')
10
10
  MAJOR = major unless const_defined?('MAJOR')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cicd-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.57
4
+ version: 0.9.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christo De Lange