lib/cicd/builder/manifest/mixlib/repo/artifactory.rb in manifest-builder-0.5.5 vs lib/cicd/builder/manifest/mixlib/repo/artifactory.rb in manifest-builder-0.5.6

- old
+ new

@@ -36,10 +36,22 @@ @logger.error "The path to the PROJECTS_FILE (#{File.dirname(ENV['PROJECTS_FILE'])}) does not exist!" @vars[:return_code] = Errors::NO_PROJECTS_PATH end end end + @vars[:artifacts].each do |art| + if art[:data][:temp].is_a?(FalseClass) + if File.exists?(art[:data][:file]) + File.unlink(art[:data][:file]) if File.exists?(art[:data][:file]) + art[:data].delete(:file) + art[:data].delete(:temp) + else + @logger.warn "Temporary file disappeared: #{data.ai}" + @vars[:return_code] = Errors::TEMP_FILE_MISSING + end + end + end @vars[:return_code] end # --------------------------------------------------------------------------------------------------------------- def createProjectsFile @@ -85,36 +97,49 @@ mode = File::RDWR|File::CREAT|File::EXCL perm = 0600 opts = perm end + '.properties' IO.write(data[:file], data[:data]) - + data[:temp] = false data[:sha1] = Digest::SHA1.file(data[:file]).hexdigest - data[:md5] = Digest::MD5.file(data[:file]).hexdigest + data[:md5] = Digest::MD5.file(data[:file]).hexdigest data[:name] = amn - # data[:temp] = false - # @builder.addArtifact(@vars[:artifacts], local, local_dir, {module: comp[0], name: comp[0], build: build, version: version, file: local}) - @vars[:artifacts].unshift({ - key: amn, - data: data.dup, - }) + @vars[:artifacts] << { + key: amn, + data: data.dup, + } manifest[amn]={ amn => "#{@vars[:build_ver]}-#{@vars[:build_num]}" } maybeUploadArtifactoryObject(data: data, artifact_module: amn, artifact_version: data[:version] || @vars[:version], file_name: '', file_ext: 'properties') end # --------------------------------------------------------------------------------------------------------------- def createProductManifests(manifest) - manifest.each do |mod, man| + manifest.dup.each do |mod, man| manifest_data = '' man.each do |k, v| manifest_data += "#{k}=#{v}\n" end data = {module: mod, data: manifest_data, version: @vars[:build_ver], build: @vars[:build_num], properties: @properties_matrix} - tempArtifactFile("#{mod}-manifest", data) + # tempArtifactFile("#{mod}-manifest", data) + + data[:file] = Dir::Tmpname.create("#{mod}-manifest") do |tmpnam, n, opts| + mode = File::RDWR|File::CREAT|File::EXCL + perm = 0600 + opts = perm + end + '.properties' + IO.write(data[:file], data[:data]) + data[:temp] = false data[:sha1] = Digest::SHA1.file(data[:file]).hexdigest - data[:md5] = Digest::MD5.file(data[:file]).hexdigest + data[:md5] = Digest::MD5.file(data[:file]).hexdigest data[:name] = "#{mod}-manifest" + @vars[:artifacts] << { + key: "#{mod}-manifest", + data: data.dup, + } + # noinspection RubyStringKeysInHashInspection + manifest["#{mod}-manifest"]={ "#{mod}-manifest" => "#{@vars[:build_ver]}-#{@vars[:build_num]}" } + maybeUploadArtifactoryObject(data: data, artifact_module: data[:name], artifact_version: data[:version] || @vars[:version], file_name: '', file_ext: 'properties') # -#{@vars[:variant]} end end # ---------------------------------------------------------------------------------------------------------------