Skip to content

Commit

Permalink
Merge pull request #967 from sarameisburger/delete-artifactory
Browse files Browse the repository at this point in the history
(RE-12499) Add function to purge tarballs from artifactory if a compose fails
  • Loading branch information
sarameisburger authored Aug 13, 2019
2 parents 4fa5295 + 4715e48 commit 9dc1463
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/packaging/artifactory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,29 @@ def ship_pe_tarballs(tarball_path, target_repo, ship_paths)
end
end

# 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
# @param tarball_path [String] the local path to the tarballs that were shipped
# @param pe_repo [String] the artifactory repo the tarballs were shipped to
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

private :check_authorization
end
end

0 comments on commit 9dc1463

Please sign in to comment.