class Artifactory::Resource::Build

def all(name, options = {})

Returns:
  • (Array) -

Options Hash: (**options)
  • :client (Artifactory::Client) --

Parameters:
  • options (Hash) --
  • name (String) --
def all(name, options = {})
  client = extract_client!(options)
  client.get("/api/build/#{url_safe(name)}")["buildsNumbers"].map do |build_number|
    # Remove the leading / from the `uri` value. Converts `/484` to `484`.
    number = build_number["uri"].slice(1..-1)
    find(name, number, client: client)
  end.compact.flatten
rescue Error::HTTPError => e
  # Artifactory returns a 404 instead of an empty list when there are no
  # builds. Whoever decided that was a good idea clearly doesn't
  # understand the point of REST interfaces...
  raise unless e.code == 404
  []
end

def api_path

Returns:
  • (String) -
def api_path
  "/api/build/#{url_safe(name)}/#{url_safe(number)}"
end

def diff(previous_build_number)

Returns:
  • (Hash) -

Parameters:
  • previous_build_number (String) --

Other tags:
    Example: List all properties for an artifact -
def diff(previous_build_number)
  endpoint = api_path + "?" "diff=#{url_safe(previous_build_number)}"
  client.get(endpoint, {})
end

def find(name, number, options = {})

Returns:
  • (Resource::Build, nil) -

Options Hash: (**options)
  • :client (Artifactory::Client) --

Parameters:
  • options (Hash) --
  • number (String) --
  • name (String) --

Other tags:
    Example: Find data for a build of a component -
def find(name, number, options = {})
  client = extract_client!(options)
  response = client.get("/api/build/#{url_safe(name)}/#{url_safe(number)}")
  from_hash(response["buildInfo"], client: client)
rescue Error::HTTPError => e
  raise unless e.code == 404
  nil
end

def from_hash(hash, options = {})

Other tags:
    See: Artifactory::Resource::Base.from_hash -
def from_hash(hash, options = {})
  super.tap do |instance|
    instance.started = Time.parse(instance.started) rescue nil
    instance.duration_millis = instance.duration_millis.to_i
  end
end

def promote(target_repo, options = {})

Returns:
  • (Hash) -

Options Hash: (**options)
  • :fail_fast (Boolean) --
  • :properties (Hash>) --
  • :scopes (Array) --
  • :dependencies (Boolean) --
  • :copy (Boolean) --
  • :dry_run (Boolean) --
  • :user (String) --
  • :comment (String) --
  • :status (String) --

Parameters:
  • options (Hash) --
  • target_repo (String) --

Other tags:
    Example: promote a build attaching some new properites -
    Example: promote the build to 'omnibus-stable-local' -
def promote(target_repo, options = {})
  request_body = {}.tap do |body|
    body[:status]       = options[:status] || "promoted"
    body[:comment]      = options[:comment] || ""
    body[:ciUser]       = options[:user] || Artifactory.username
    body[:dryRun]       = options[:dry_run] || false
    body[:targetRepo]   = target_repo
    body[:copy]         = options[:copy] || false
    body[:artifacts]    = true # always move/copy the build's artifacts
    body[:dependencies] = options[:dependencies] || false
    body[:scopes]       = options[:scopes] || []
    body[:properties]   = options[:properties] || {}
    body[:failFast]     = options[:fail_fast] || true
  end
  endpoint = "/api/build/promote/#{url_safe(name)}/#{url_safe(number)}"
  client.post(endpoint, JSON.fast_generate(request_body),
    "Content-Type" => "application/json")
end

def save

Returns:
  • (Boolean) -
def save
  raise Error::InvalidBuildType.new(type) unless BUILD_TYPES.include?(type)
  file = Tempfile.new("build.json")
  file.write(to_json)
  file.rewind
  client.put("/api/build", file,
    "Content-Type" => "application/json")
  true
ensure
  if file
    file.close
    file.unlink
  end
end