Class: Pkg::ManageArtifactory

Inherits:
Object
  • Object
show all
Defined in:
lib/packaging/artifactory.rb

Overview

The Artifactory class This class provides automation to access the artifactory repos maintained by the Release Engineering team at Puppet. It has the ability to both push artifacts to the repos, and to retrieve them back from the repos.

Constant Summary collapse

ARTIFACTORY_CLEANUP_SKIP_PROPERTY =

The Artifactory property that the artifactCleanup user plugin https://github.com/jfrog/artifactory-user-plugins/tree/master/cleanup/artifactCleanup uses to tell it to not clean a particular artifact

'cleanup.skip'
DEFAULT_REPO_TYPE =
'generic'
DEFAULT_REPO_BASE =
'development'

Instance Method Summary collapse

Constructor Details

#initialize(project, project_version, opts = {}) ⇒ ManageArtifactory

Returns a new instance of ManageArtifactory.

Parameters:

  • project (String)

    The name of the project this package is for

  • project_version (String)

    The version of the project we want the package for. This can be one of three things:

    1) the final tag of the project the packages  were built from
    2) the long git sha the project the packages were built from
    3) the EZBake generated development sha where the packages live
    
  • :artifactory_uri (Hash)

    a customizable set of options

  • :repo_base (Hash)

    a customizable set of options



93
94
95
96
97
98
99
100
101
# File 'lib/packaging/artifactory.rb', line 93

def initialize(project, project_version, opts = {})
  @artifactory_uri = opts[:artifactory_uri] || 'https://artifactory.delivery.puppetlabs.net/artifactory'
  @repo_base = opts[:repo_base] || DEFAULT_REPO_BASE

  @project = project
  @project_version = project_version

  Artifactory.endpoint = @artifactory_uri
end

Instance Method Details

#all_package_names(platform_data, platform_tag) ⇒ Array

Returns An array containing all packages for the given project, project_version, and platform_tag.

Parameters:

  • platform_data (Hash)

    The hash of the platform data that needs to be parsed

  • platform_tag (String)

    The tag that the data we want belongs to

Returns:

  • (Array)

    An array containing all packages for the given project, project_version, and platform_tag



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/packaging/artifactory.rb', line 327

def all_package_names(platform_data, platform_tag)
  packages = [platform_data[platform_tag][:artifact]]
  packages << platform_data[platform_tag][:additional_artifacts]
  packages.flatten!
  packages.reject! { |package| package.nil? || package.empty? }
  packages.map { |package| File.basename(package) }
rescue
  fail_message = <<-DOC
  Package name could not be found from loaded yaml data. Either this package
  does not exist, or '#{platform_tag}' is not present in this dataset.

  The following are available platform tags for '#{@project}' '#{@project_version}':
#{platform_data.keys.sort}
  DOC
  raise fail_message
end

#copy_final_pe_tarballs(pe_version, repo, remote_path, target_path) ⇒ Object

When we ship a new PE release we copy final tarballs to archives/releases

Parameters:

  • pe_version (String)

    pe final tag

  • repo (String)

    repo the tarballs live

  • remote_path (String)

    path to tarballs in the repo

  • target_path (String)

    path copy tarballs to, assumes same repo



554
555
556
557
558
559
560
561
562
# File 'lib/packaging/artifactory.rb', line 554

def copy_final_pe_tarballs(pe_version, repo, remote_path, target_path)
  check_authorization
  final_tarballs = Artifactory::Resource::Artifact.search(name: pe_version, repos: repo)
  final_tarballs.each do |artifact|
    next unless artifact.download_uri.include? remote_path
    next if artifact.download_uri.include? "-rc"
    artifact.copy("#{repo}/#{target_path}")
  end
end

#deb_list_contents(platform_tag) ⇒ String

Returns The contents of the debian list file to enable the debian artifactory repos for the specified project and version.

Parameters:

  • platform_tag (String)

    The platform to generate the list contents for

Returns:

  • (String)

    The contents of the debian list file to enable the debian artifactory repos for the specified project and version



173
174
175
176
177
178
179
# File 'lib/packaging/artifactory.rb', line 173

def deb_list_contents(platform_tag)
  data = platform_specific_data(platform_tag)
  if data[:package_format] == 'deb'
    return "deb #{@artifactory_uri}/#{data[:repo_name]} #{data[:codename]} #{data[:repo_subdirectories]}"
  end
  raise "The platform '#{platform_tag}' is not an apt-based system."
end

#deploy_package(package) ⇒ Object

Parameters:

  • package (String)

    The full relative path to the package to be shipped, relative from the current working directory



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/packaging/artifactory.rb', line 274

def deploy_package(package)
  platform_tag = Pkg::Paths.tag_from_artifact_path(package) || DEFAULT_REPO_TYPE
  data = platform_specific_data(platform_tag)

  check_authorization
  artifact = Artifactory::Resource::Artifact.new(local_path: package)
  artifact_md5 = Digest::MD5.file(package).hexdigest
  headers = { "X-Checksum-Md5" => artifact_md5 }
  artifact.upload(
    data[:repo_name],
    File.join(data[:alternate_subdirectories], File.basename(package)),
    deploy_properties(platform_tag),
    headers
  )
rescue
  raise "Attempt to upload '#{package}' to #{File.join(@artifactory_uri, data[:full_artifactory_path])} failed"
end

#deploy_properties(platform_tag) ⇒ String

Returns Any required extra bits that we need for the curl command used to deploy packages to artifactory

These are a few examples from chef/artifactory-client. These could potentially be very powerful, but we should decide how to use them.

status: 'DEV',
rating: 5,
branch: 'master'

Currently we are including everything that would be included in the yaml file that is generated at package build time.

Parameters:

  • platform_tag (String)

    The platform tag to generate deploy properties for

Returns:

  • (String)

    Any required extra bits that we need for the curl command used to deploy packages to artifactory

    These are a few examples from chef/artifactory-client. These could potentially be very powerful, but we should decide how to use them.

    status: 'DEV',
    rating: 5,
    branch: 'master'
    

    Currently we are including everything that would be included in the yaml file that is generated at package build time.



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/packaging/artifactory.rb', line 238

def deploy_properties(platform_tag)
  data = platform_specific_data(platform_tag)

  # TODO This method should be returning the entire contents of the yaml
  # file in hash form to include as metadata for these artifacts. In this
  # current iteration, the hash isn't formatted properly and the attempt to
  # deploy to Artifactory bails out. I'm leaving this in so that we at least
  # have multiple places to remind us that it needs to happen.
  #properties_hash = Pkg::Config.config_to_hash
  properties_hash = {}
  if data[:package_format] == 'deb'
    properties_hash.merge!({
      'deb.distribution' => data[:codename],
      'deb.component' => data[:repo_subdirectories],
      'deb.architecture' => data[:architecture],
    })
  end
  properties_hash
end

#download_artifact(artifact_name, repo, path) ⇒ Object

Download an artifact based on name, repo, and path to artifact

Parameters:

  • artifact_name (String)

    name of artifact to download

  • repo (String)

    repo the artifact lives

  • path (String)

    path to artifact in the repo



510
511
512
513
514
515
516
517
518
# File 'lib/packaging/artifactory.rb', line 510

def download_artifact(artifact_name, repo, path)
  check_authorization
  artifacts = Artifactory::Resource::Artifact.search(name: artifact_name, repos: repo)
  artifacts.each do |artifact|
    if artifact.download_uri.include? path
      artifact.download('.')
    end
  end
end

#download_beta_pe_tarballs(beta_tag, repo, remote_path, local_path) ⇒ Object

Download beta pe tarballs to local path based on tag, repo, and path on artifactory

Parameters:

  • beta_tag (String)

    rc tag of beta release ex. 2019.2.0-rc10

  • repo (String)

    repo the tarballs live

  • remote_path (String)

    path to tarballs in the repo

  • local_path (String)

    local path to download tarballs to



540
541
542
543
544
545
546
547
# File 'lib/packaging/artifactory.rb', line 540

def download_beta_pe_tarballs(beta_tag, repo, remote_path, local_path)
  check_authorization
  pattern = "#{remote_path}/*-#{beta_tag}-*"
  artifacts = Artifactory::Resource::Artifact.pattern_search(repo: repo, pattern: pattern)
  artifacts.each do |artifact|
    artifact.download(local_path)
  end
end

#download_final_pe_tarballs(pe_version, repo, remote_path, local_path) ⇒ Object

Download final pe tarballs to local path based on name, repo, and path on artifactory

Parameters:

  • pe_version (String)

    pe final tag

  • repo (String)

    repo the tarballs live

  • remote_path (String)

    path to tarballs in the repo

  • local_path (String)

    local path to download tarballs to



525
526
527
528
529
530
531
532
533
# File 'lib/packaging/artifactory.rb', line 525

def download_final_pe_tarballs(pe_version, repo, remote_path, local_path)
  check_authorization
  artifacts = Artifactory::Resource::Artifact.search(name: pe_version, repos: repo)
  artifacts.each do |artifact|
    next unless artifact.download_uri.include? remote_path
    next if artifact.download_uri.include? "-rc"
    artifact.download(local_path)
  end
end

#download_packages(staging_directory, manifest) ⇒ Object

Using the manifest provided by enterprise-dist, grab the appropropriate packages from artifactory based on md5sum

Parameters:

  • staging_directory (String)

    location to download packages to

  • manifest (File)

    JSON file containing information about what packages to download and the corresponding md5sums



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/packaging/artifactory.rb', line 411

def download_packages(staging_directory, manifest)
  check_authorization
  manifest.each do |dist, packages|
    puts "Grabbing the #{dist} packages from artifactory"
    packages.each do |name, info|
      artifact_to_download = Artifactory::Resource::Artifact.checksum_search(md5: "#{info["md5"]}", repos: ["rpm_enterprise__local", "debian_enterprise__local"]).first
      if artifact_to_download.nil?
        raise "Error: what the hell, could not find package #{info["filename"]} with md5sum #{info["md5"]}"
      else
        puts "downloading #{artifact_to_download.download_uri}"
        artifact_to_download.download("#{staging_directory}/#{dist}", filename: "#{info["filename"]}")
      end
    end
  end
end

#location_for(platform_tag) ⇒ Array

Returns An array containing three items, first being the main repo name for the platform_tag, the second being the subdirectories of the repo leading to the artifact we want to install, and the third being the alternate subdirectories for a given repo. This last option is only currently used for debian platforms, where the path to the repo specified in the list file is different than the full path to the repo.

Parameters:

  • platform_tag (String)

    The platform tag string for the repo we need information on. If generic information is needed, pass in ‘generic`

Returns:

  • (Array)

    An array containing three items, first being the main repo name for the platform_tag, the second being the subdirectories of the repo leading to the artifact we want to install, and the third being the alternate subdirectories for a given repo. This last option is only currently used for debian platforms, where the path to the repo specified in the list file is different than the full path to the repo.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/packaging/artifactory.rb', line 111

def location_for(platform_tag)
  toplevel_repo = DEFAULT_REPO_TYPE
  repo_subdirectories = File.join(@repo_base, @project, @project_version)
  alternate_subdirectories = repo_subdirectories

  unless platform_tag == DEFAULT_REPO_TYPE
    format = Pkg::Platforms.package_format_for_tag(platform_tag)
    platform, version, architecture = Pkg::Platforms.parse_platform_tag(platform_tag)
  end

  case format
  when 'rpm'
    toplevel_repo = 'rpm'
    repo_subdirectories = File.join(repo_subdirectories, "#{platform}-#{version}-#{architecture}")
    alternate_subdirectories = repo_subdirectories
  when 'deb'
    toplevel_repo = 'debian__local'
    repo_subdirectories = File.join(repo_subdirectories, "#{platform}-#{version}")
    alternate_subdirectories = File.join('pool', repo_subdirectories)
  when 'swix', 'dmg', 'svr4', 'ips'
    repo_subdirectories = File.join(repo_subdirectories, "#{platform}-#{version}-#{architecture}")
    alternate_subdirectories = repo_subdirectories
  when 'msi'
    repo_subdirectories = File.join(repo_subdirectories, "#{platform}-#{architecture}")
    alternate_subdirectories = repo_subdirectories
  end

  [toplevel_repo, repo_subdirectories, alternate_subdirectories]
end

#package_exists_on_artifactory?(package) ⇒ Boolean

Basic method to check if a package exists on artifactory Return true if package already exists on artifactory

Parameters:

  • package (String)

    The full relative path to the package to be checked, relative from the current working directory

Returns:

  • (Boolean)


262
263
264
265
266
267
268
269
270
# File 'lib/packaging/artifactory.rb', line 262

def package_exists_on_artifactory?(package)
  check_authorization
  artifact = Artifactory::Resource::Artifact.search(name: File.basename(package), :artifactory_uri => @artifactory_uri)
  if artifact.empty?
    return false
  else
    return true
  end
end

#package_name(platform_data, platform_tag) ⇒ String

Returns The name of the package for the given project, project_version, and platform_tag.

Parameters:

  • platform_data (Hash)

    The hash of the platform data that needs to be parsed

  • platform_tag (String)

    The tag that the data we want belongs to

Returns:

  • (String)

    The name of the package for the given project, project_version, and platform_tag



309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/packaging/artifactory.rb', line 309

def package_name(platform_data, platform_tag)
  return File.basename(platform_data[platform_tag][:artifact])
rescue
  fail_message = <<-DOC
  Package name could not be found from loaded yaml data. Either this package
  does not exist, or '#{platform_tag}' is not present in this dataset.

  The following are available platform tags for '#{@project}' '#{@project_version}':
#{platform_data.keys.sort}
  DOC
  raise fail_message
end

#platform_specific_data(platform_tag) ⇒ Hash

Returns a hash of data specific to this platform tag

Parameters:

  • platform_tag (String)

    The platform tag specific to the information we need. If only the generic information is needed, pass in ‘generic`

Returns:

  • (Hash)

    Returns a hash of data specific to this platform tag



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/packaging/artifactory.rb', line 144

def platform_specific_data(platform_tag)
  unless platform_tag == DEFAULT_REPO_TYPE
    platform, version, architecture = Pkg::Platforms.parse_platform_tag(platform_tag)
    package_format = Pkg::Platforms.package_format_for_tag(platform_tag)
    if package_format == 'deb'
      codename = Pkg::Platforms.codename_for_platform_version(platform, version)
    end
  end

  repo_name, repo_subdirectories, alternate_subdirectories = location_for(platform_tag)
  full_artifactory_path = File.join(repo_name, alternate_subdirectories)

  {
    platform: platform,
    platform_version: version,
    architecture: architecture,
    codename: codename,
    package_format: package_format,
    repo_name: repo_name,
    repo_subdirectories: repo_subdirectories,
    alternate_subdirectories: alternate_subdirectories,
    full_artifactory_path: full_artifactory_path
  }
end

#populate_pe_repos(manifest, target_path) ⇒ Object

When we cut a new PE branch, we need to copy the pe components into <pe_version>/repos,feature,release/<platform>

Parameters:

  • manifest (File)

    JSON file containing information about what packages to download and the corresponding md5sums

  • target_path (String)

    path on artifactory to copy components to, e.g. <pe_version>/release



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# File 'lib/packaging/artifactory.rb', line 567

def populate_pe_repos(manifest, target_path)
  check_authorization
  manifest.each do |dist, packages|
    puts "Copying #{dist} packages..."
    packages.each do |name, info|
      artifact = Artifactory::Resource::Artifact.checksum_search(md5: "#{info["md5"]}", repos: ["rpm_enterprise__local", "debian_enterprise__local"]).first
      if artifact.nil?
        raise "Error: what the hell, could not find package #{info["filename"]} with md5sum #{info["md5"]}"
      end
      begin
        artifact_target_path = "#{artifact.repo}/#{target_path}/#{dist}/#{info["filename"]}"
        puts "Copying #{artifact.download_uri} to #{artifact_target_path}"
        artifact.copy(artifact_target_path)
      rescue Artifactory::Error::HTTPError
        STDERR.puts "Could not copy #{artifact_target_path}. Source and destination are the same. Skipping..."
      end
    end
  end
end

#promote_package(pkg, ref, platform_tag, repository, debian_component = nil) ⇒ Object

Promotes a build based on build SHA or tag (or SNAPSHOT version, for ezbake) Depending on if it’s an RPM or Deb package promote accordingly ‘promote’ by copying the package(s) to the enterprise directory on artifactory

Parameters:

  • pkg (String)

    the package name ex. puppet-agent

  • ref (String)

    tag or SHA of package(s) to be promoted

  • platform_tag (String)

    the platform tag of the artifact ex. el-7-x86_64, ubuntu-18.04-amd64

  • repository (String)

    the repository to promote the artifact to. Will prepend ‘rpm_’ or ‘debian_’ to the repositories depending on package type

  • debian_component (String) (defaults to: nil)

    the debian component to promote packages into. Optional.



357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/packaging/artifactory.rb', line 357

def promote_package(pkg, ref, platform_tag, repository, debian_component = nil)
  # load package metadata
  yaml_content = retrieve_yaml_data(pkg, ref)
  yaml_data = YAML::load(yaml_content)

  # get the artifact name
  artifact_names = all_package_names(yaml_data[:platform_data], platform_tag)
  artifact_names.each do |artifact_name|
    artifact_search_results = Artifactory::Resource::Artifact.search(
      name: artifact_name, :artifactory_uri => @artifactory_uri)

    if artifact_search_results.empty?
      raise "Error: could not find PKG=#{pkg} at REF=#{git_ref} for #{platform_tag}"
    end
    artifact_to_promote = artifact_search_results[0]

    # This makes an assumption that we're using some consistent repo names
    # but need to either prepend 'rpm_' or 'debian_' based on package type
    case File.extname(artifact_name)
    when '.rpm'
      promotion_path = "rpm_#{repository}/#{platform_tag}/#{artifact_name}"
    when '.deb'
      promotion_path = "debian_#{repository}/#{platform_tag}/#{artifact_name}"
      properties = { 'deb.component' => debian_component } unless debian_component.nil?
    else
      raise "Error: Unknown promotion repository for #{artifact_name}! Only .rpm and .deb files are supported!"
    end

    begin
      source_path = artifact_to_promote.download_uri.sub(@artifactory_uri, '')
      puts "promoting #{artifact_name} from #{source_path} to #{promotion_path}"
      artifact_to_promote.copy(promotion_path)
      unless properties.nil?
        artifacts = Artifactory::Resource::Artifact.search(name: artifact_name, :artifactory_uri => @artifactory_uri)
        promoted_artifact = artifacts.select { |artifact| artifact.download_uri =~ %r{#{promotion_path}} }.first
        promoted_artifact.properties(properties)
      end
    rescue Artifactory::Error::HTTPError => e
      if e.message =~ /(destination and source are the same|user doesn't have permissions to override)/i
        puts "Skipping promotion of #{artifact_name}; it has already been promoted"
      else
        puts "#{e.message}"
        raise e
      end
    rescue => e
      puts "Something went wrong promoting #{artifact_name}!"
      raise e
    end
  end
end

#purge_copied_pe_tarballs(tarball_path, pe_repo) ⇒ Object

Remove shipped PE tarballs from artifactory Used when compose fails, we only want the tarball shipped to artifactory if all platforms succeed Identify which packages were created and shipped based on md5sum and remove them

Parameters:

  • tarball_path (String)

    the local path to the tarballs that were shipped

  • pe_repo (String)

    the artifactory repo the tarballs were shipped to



606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'lib/packaging/artifactory.rb', line 606

def purge_copied_pe_tarballs(tarball_path, pe_repo)
  check_authorization
  Dir.foreach("#{tarball_path}/") do |pe_tarball|
    next if pe_tarball == '.' || pe_tarball == ".."
    md5 = Digest::MD5.file("#{tarball_path}/#{pe_tarball}").hexdigest
    artifacts_to_delete = Artifactory::Resource::Artifact.checksum_search(md5: md5, repos: pe_repo)
    next if artifacts_to_delete.nil?
    begin
      artifacts_to_delete.each do |artifact|
        puts "Removing #{pe_tarball} from #{pe_repo}... "
        artifact.delete
      end
    rescue Artifactory::Error::HTTPError
      STDERR.puts "Error: cannot remove #{pe_tarball}, do you have the right permissions?"
    end
  end
end

#retrieve_yaml_data(pkg, ref) ⇒ String

Returns The contents of the YAML file.

Parameters:

  • pkg (String)

    The package to download YAML for i.e. ‘puppet-agent’ or ‘puppetdb’

  • ref (String)

    The git ref (sha or tag) we want the YAML for

Returns:

  • (String)

    The contents of the YAML file



297
298
299
300
301
302
# File 'lib/packaging/artifactory.rb', line 297

def retrieve_yaml_data(pkg, ref)
  yaml_url = "#{@artifactory_uri}/#{DEFAULT_REPO_TYPE}/#{DEFAULT_REPO_BASE}/#{pkg}/#{ref}/#{ref}.yaml"
  open(yaml_url) { |f| f.read }
rescue
  raise "Failed to load YAML data for #{pkg} at #{ref} from #{yaml_url}!"
end

#rpm_repo_contents(platform_tag) ⇒ String

Returns The contents of the rpm repo file to enable the rpm artifactory repo for the specified project and version.

Parameters:

  • platform_tag (String)

    The platform to generate the repo file contents for

Returns:

  • (String)

    The contents of the rpm repo file to enable the rpm artifactory repo for the specified project and version



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/packaging/artifactory.rb', line 185

def rpm_repo_contents(platform_tag)
  data = platform_specific_data(platform_tag)
  if data[:package_format] == 'rpm'
    return <<-DOC
  [Artifactory #{@project} #{@project_version} for #{platform_tag}]
  name=Artifactory Repository for #{@project} #{@project_version} for #{platform_tag}
  baseurl=#{@artifactory_uri}/#{data[:repo_name]}/#{data[:repo_subdirectories]}
  enabled=1
  gpgcheck=0
  #Optional - if you have GPG signing keys installed, use the below flags to verify the repository metadata signature:
  #gpgkey=#{@artifactory_uri}/#{data[:repo_name]}/#{data[:repo_subdirectories]}/repomd.xml.key
  #repo_gpgcheck=1
    DOC
  end
  raise "The platform '#{platform_tag}' is not a yum-based system"
end

#ship_pe_tarballs(local_tarball_directory, target_repo, ship_paths) ⇒ Object

Ship PE tarballs to specified artifactory repo and paths

Parameters:

  • local_tarball_directory (String)

    the local directory containing the tarballs

  • target_repo (String)

    the artifactory repo to ship the tarballs to

  • ship_paths (Array)

    the artifactory path(s) to ship the tarballs to within the target_repo



432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/packaging/artifactory.rb', line 432

def ship_pe_tarballs(local_tarball_directory, target_repo, ship_paths)
  check_authorization
  ship_paths.each do |path|
    unset_cleanup_skip_on_artifacts(target_repo, path)
    Dir.foreach(local_tarball_directory) do |pe_tarball|
      next if pe_tarball == '.' || pe_tarball == ".."
      begin
        puts "Uploading #{pe_tarball} to #{target_repo}/#{path}#{pe_tarball}"
        artifact = Artifactory::Resource::Artifact.new(
          local_path: "#{local_tarball_directory}/#{pe_tarball}")
        uploaded_artifact = artifact.upload(target_repo, "#{path}#{pe_tarball}")
        # The Artifactory gem property setter only works when '/api/storage' is used in
        # the 'uri' field.
        # Strangely, the above Artifactory::Resource::Artifact.new gives us the raw URI.
        # Therefore we are forced to do some path surgery, inserting
        # '/api/storage' before "/#{target_repo}" to make the property setting work.
        storage_artifact = uploaded_artifact
        unless storage_artifact.uri.include?("/api/storage")
          storage_artifact.uri = storage_artifact.uri.sub(
            "/#{target_repo}",
            "/api/storage/#{target_repo}")
        end
        storage_artifact.properties(ARTIFACTORY_CLEANUP_SKIP_PROPERTY => true)
      rescue Errno::EPIPE
        ## [eric.griswold] maybe this should be fatal?
        STDERR.puts "Warning: Could not upload #{pe_tarball} to #{target_repo}/#{path}. Skipping."
        next
      end
    end
  end
end

#teardown_repo(repos, pattern) ⇒ Object

Remove all artifacts in repo based on pattern, used when we purge all artifacts in release/ after PE release

Parameters:

  • repos (Array)

    repos that we want to search for artifacts in

  • pattern (String)

    pattern for artifacts that should be deleted ex. ‘2019.1/release//`



590
591
592
593
594
595
596
597
598
599
# File 'lib/packaging/artifactory.rb', line 590

def teardown_repo(repos, pattern)
  check_authorization
  repos.each do |repo|
    artifacts = Artifactory::Resource::Artifact.pattern_search(repo: repo, pattern: pattern)
    artifacts.each do |artifact|
      puts "Deleting #{artifact.download_uri}"
      artifact.delete
    end
  end
end

#unset_cleanup_skip_on_artifacts(repo, directory) ⇒ Object

Clear the ARTIFACTORY_CLEANUP_SKIP_PROPERTY on all artifacts in a specified directory in a given Artifactory repo that match /<directory>/*.tar. Use this before uploading newer tarballs to maintain ‘cleanup.skip’ on the latest tarballs only.

Parameters:

  • repo (String)

    Artifactory repository that contains the specified directory

  • directory (String)

    Artifactory directory in repo containing the artifacts from which to set the ‘cleanup.skip’ property setting to false



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# File 'lib/packaging/artifactory.rb', line 489

def unset_cleanup_skip_on_artifacts(repo, directory)
  artifacts_with_cleanup_skip = Artifactory::Resource::Artifact.property_search(
    ARTIFACTORY_CLEANUP_SKIP_PROPERTY => true,
    "repos" => repo
  )

  # For the upcoming directory check, make sure we know where our trailing slashes are.
  directory_no_trailing_slashes = directory.sub(/(\/)+$/, '')

  # For all tarball artifacts in #{directory} that have the Artifactory property
  # 'cleanup.skip' set to true, set it to 'false'
  artifacts_with_cleanup_skip.each do |artifact|
    next unless artifact.uri.include?("/#{directory_no_trailing_slashes}/")
    artifact.properties(ARTIFACTORY_CLEANUP_SKIP_PROPERTY => false)
  end
end

#upload_file(local_path, target_repo, target_path) ⇒ Object

Upload file to Artifactory

Parameters:

  • local_path (String)

    local path to file to upload

  • target_repo (String)

    repo on artifactory to upload to

  • target_path (String)

    path within target_repo to upload to



468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/packaging/artifactory.rb', line 468

def upload_file(local_path, target_repo, target_path)
  fail "Error: Couldn't find file at #{local_path}." unless File.exist? local_path
  check_authorization
  artifact = Artifactory::Resource::Artifact.new(local_path: local_path)
  full_upload_path = File.join(target_path, File.basename(local_path))
  begin
    puts "Uploading #{local_path} to #{target_repo}/#{full_upload_path} . . ."
    artifact.upload(target_repo, full_upload_path)
  rescue Artifactory::Error::HTTPError => e
    fail "Error: Upload failed. Ensure path #{target_path} exists in the #{target_repo} repository."
  end
end