Class: Omnibus::ArtifactoryPublisher

Inherits:
Publisher
  • Object
show all
Defined in:
lib/omnibus/publishers/artifactory_publisher.rb

Instance Method Summary collapse

Methods inherited from Publisher

#initialize, #packages, publish

Methods included from Logging

included

Constructor Details

This class inherits a constructor from Omnibus::Publisher

Instance Method Details

#publish(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/omnibus/publishers/artifactory_publisher.rb', line 22

def publish(&block)
  log.info(log_key) { 'Starting artifactory publisher' }
  safe_require('artifactory')

  packages.each do |package|
    # Make sure the package is good to go!
    log.debug(log_key) { "Validating '#{package.name}'" }
    package.validate!

    # Upload the actual package
    log.info(log_key) { "Uploading '#{package.name}'" }

    retries = Config.publish_retries

    begin
      upload_time = Benchmark.realtime do
        artifact_for(package).upload(
          repository,
          remote_path_for(package),
          default_properties.merge((package)),
        )
      end
    rescue Artifactory::Error::HTTPError => e
      if (retries -= 1) != 0
        log.info(log_key) { "Upload failed with exception: #{e}"}
        log.info(log_key) { "Retrying failed publish #{retries} more time(s)..." }
        retry
      else
        raise e
      end
    end

    log.debug(log_key)  { "Elapsed time to publish #{package.name}:  #{1000*upload_time} ms" }

    # If a block was given, "yield" the package to the caller
    block.call(package) if block
  end

  if build_record?
    if packages.empty?
      log.warn(log_key) { "No packages were uploaded, build record will not be created." }
    else
      build_for(packages).save
    end
  end
end