Class: Artifactory::Resource::Build

Inherits:
Base
  • Object
show all
Defined in:
lib/artifactory/resources/build.rb

Constant Summary collapse

BUILD_SCHEMA_VERSION =
'1.0.1'.freeze
BUILD_TYPES =

valid build types as dictated by the Artifactory API

%w( ANT IVY MAVEN GENERIC GRADLE )

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

attribute, attributes, #attributes, #client, #client=, #client?, #extract_client!, extract_client!, find_from_config, format_repos!, #format_repos!, from_url, has_attribute?, #initialize, #inspect, list_from_config, #set, #to_hash, #to_json, #to_matrix_properties, #to_query_string_parameters, #to_s, url_safe, #url_safe

Constructor Details

This class inherits a constructor from Artifactory::Resource::Base

Class Method Details

.all(name, options = {}) ⇒ Array<Resource::Build>

Search for all builds in the system.

Parameters:

  • name (String)

    the name of the build component

  • options (Hash) (defaults to: {})

    the list of options

Options Hash (options):

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/artifactory/resources/build.rb', line 40

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

.find(name, number, options = {}) ⇒ Resource::Build?

Find (fetch) data for a particular build of a component

Examples:

Find data for a build of a component

Build.find('wicket', 25) #=> #<Build name: 'wicket' ...>

Parameters:

  • name (String)

    the name of the build component

  • number (String)

    the number of the build

  • options (Hash) (defaults to: {})

    the list of options

Options Hash (options):

Returns:

  • (Resource::Build, nil)

    an instance of the build that matches the given name/number combination, or nil if one does not exist



75
76
77
78
79
80
81
82
# File 'lib/artifactory/resources/build.rb', line 75

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

.from_hash(hash, options = {}) ⇒ Object



87
88
89
90
91
92
# File 'lib/artifactory/resources/build.rb', line 87

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

Instance Method Details

#agentObject

Return this object’s agent

Returns:

  • (Object)


102
# File 'lib/artifactory/resources/build.rb', line 102

attribute :agent, {}

#agent=(value) ⇒ Object

Set this object’s agent

Parameters:

  • value (Object)

    the value to set for agent

  • default (Object)

    the default value for this attribute



102
# File 'lib/artifactory/resources/build.rb', line 102

attribute :agent, {}

#agent?Boolean

Determines if the agent value exists and is truthy

Returns:

  • (Boolean)


102
# File 'lib/artifactory/resources/build.rb', line 102

attribute :agent, {}

#artifactory_principalObject

Return this object’s artifactory_principal

Returns:

  • (Object)


105
# File 'lib/artifactory/resources/build.rb', line 105

attribute :artifactory_principal

#artifactory_principal=(value) ⇒ Object

Set this object’s artifactory_principal

Parameters:

  • value (Object)

    the value to set for artifactory_principal

  • default (Object)

    the default value for this attribute



105
# File 'lib/artifactory/resources/build.rb', line 105

attribute :artifactory_principal

#artifactory_principal?Boolean

Determines if the artifactory_principal value exists and is truthy

Returns:

  • (Boolean)


105
# File 'lib/artifactory/resources/build.rb', line 105

attribute :artifactory_principal

#build_agentObject

Return this object’s build_agent

Returns:

  • (Object)


101
# File 'lib/artifactory/resources/build.rb', line 101

attribute :build_agent, {}

#build_agent=(value) ⇒ Object

Set this object’s build_agent

Parameters:

  • value (Object)

    the value to set for build_agent

  • default (Object)

    the default value for this attribute



101
# File 'lib/artifactory/resources/build.rb', line 101

attribute :build_agent, {}

#build_agent?Boolean

Determines if the build_agent value exists and is truthy

Returns:

  • (Boolean)


101
# File 'lib/artifactory/resources/build.rb', line 101

attribute :build_agent, {}

#build_retentionObject

Return this object’s build_retention

Returns:

  • (Object)


110
# File 'lib/artifactory/resources/build.rb', line 110

attribute :build_retention, {}

#build_retention=(value) ⇒ Object

Set this object’s build_retention

Parameters:

  • value (Object)

    the value to set for build_retention

  • default (Object)

    the default value for this attribute



110
# File 'lib/artifactory/resources/build.rb', line 110

attribute :build_retention, {}

#build_retention?Boolean

Determines if the build_retention value exists and is truthy

Returns:

  • (Boolean)


110
# File 'lib/artifactory/resources/build.rb', line 110

attribute :build_retention, {}

#diff(previous_build_number) ⇒ Hash<String, Hash>

Compare a build artifacts/dependencies/environment with an older build to see what has changed (new artifacts added, old dependencies deleted etc).

Examples:

List all properties for an artifact

build.diff(35) #=> { 'artifacts'=>{}, 'dependencies'=>{}, 'properties'=>{} }

Parameters:

  • previous_build_number (String)

    the number of the previous build to compare against

Returns:

  • (Hash<String, Hash>)

    the list of properties



128
129
130
131
# File 'lib/artifactory/resources/build.rb', line 128

def diff(previous_build_number)
  endpoint = api_path + '?' "diff=#{url_safe(previous_build_number)}"
  client.get(endpoint, {})
end

#duration_millisObject

Return this object’s duration_millis

Returns:

  • (Object)


104
# File 'lib/artifactory/resources/build.rb', line 104

attribute :duration_millis

#duration_millis=(value) ⇒ Object

Set this object’s duration_millis

Parameters:

  • value (Object)

    the value to set for duration_millis

  • default (Object)

    the default value for this attribute



104
# File 'lib/artifactory/resources/build.rb', line 104

attribute :duration_millis

#duration_millis?Boolean

Determines if the duration_millis value exists and is truthy

Returns:

  • (Boolean)


104
# File 'lib/artifactory/resources/build.rb', line 104

attribute :duration_millis

#governanceObject

Return this object’s governance

Returns:

  • (Object)


112
# File 'lib/artifactory/resources/build.rb', line 112

attribute :governance

#governance=(value) ⇒ Object

Set this object’s governance

Parameters:

  • value (Object)

    the value to set for governance

  • default (Object)

    the default value for this attribute



112
# File 'lib/artifactory/resources/build.rb', line 112

attribute :governance

#governance?Boolean

Determines if the governance value exists and is truthy

Returns:

  • (Boolean)


112
# File 'lib/artifactory/resources/build.rb', line 112

attribute :governance

#license_controlObject

Return this object’s license_control

Returns:

  • (Object)


109
# File 'lib/artifactory/resources/build.rb', line 109

attribute :license_control, {}

#license_control=(value) ⇒ Object

Set this object’s license_control

Parameters:

  • value (Object)

    the value to set for license_control

  • default (Object)

    the default value for this attribute



109
# File 'lib/artifactory/resources/build.rb', line 109

attribute :license_control, {}

#license_control?Boolean

Determines if the license_control value exists and is truthy

Returns:

  • (Boolean)


109
# File 'lib/artifactory/resources/build.rb', line 109

attribute :license_control, {}

#modulesObject

Return this object’s modules

Returns:

  • (Object)


111
# File 'lib/artifactory/resources/build.rb', line 111

attribute :modules, []

#modules=(value) ⇒ Object

Set this object’s modules

Parameters:

  • value (Object)

    the value to set for modules

  • default (Object)

    the default value for this attribute



111
# File 'lib/artifactory/resources/build.rb', line 111

attribute :modules, []

#modules?Boolean

Determines if the modules value exists and is truthy

Returns:

  • (Boolean)


111
# File 'lib/artifactory/resources/build.rb', line 111

attribute :modules, []

#nameObject

Return this object’s name

Returns:

  • (Object)


98
# File 'lib/artifactory/resources/build.rb', line 98

attribute :name, ->{ raise 'Build component missing!' }

#name=(value) ⇒ Object

Set this object’s name

Parameters:

  • value (Object)

    the value to set for name

  • default (Object)

    the default value for this attribute



98
# File 'lib/artifactory/resources/build.rb', line 98

attribute :name, ->{ raise 'Build component missing!' }

#name?Boolean

Determines if the name value exists and is truthy

Returns:

  • (Boolean)


98
# File 'lib/artifactory/resources/build.rb', line 98

attribute :name, ->{ raise 'Build component missing!' }

#numberObject

Return this object’s number

Returns:

  • (Object)


99
# File 'lib/artifactory/resources/build.rb', line 99

attribute :number, ->{ raise 'Build number missing!' }

#number=(value) ⇒ Object

Set this object’s number

Parameters:

  • value (Object)

    the value to set for number

  • default (Object)

    the default value for this attribute



99
# File 'lib/artifactory/resources/build.rb', line 99

attribute :number, ->{ raise 'Build number missing!' }

#number?Boolean

Determines if the number value exists and is truthy

Returns:

  • (Boolean)


99
# File 'lib/artifactory/resources/build.rb', line 99

attribute :number, ->{ raise 'Build number missing!' }

#promote(target_repo, options = {}) ⇒ Hash

Move a build’s artifacts to a new repository optionally moving or copying the build’s dependencies to the target repository and setting properties on promoted artifacts.

Examples:

promote the build to ‘omnibus-stable-local’

build.promote('omnibus-stable-local')

promote a build attaching some new properites

build.promote('omnibus-stable-local'
  properties: {
    'promoted_by' => 'hipchat:[email protected]'
  }
)

Parameters:

  • target_repo (String)

    repository to move or copy the build’s artifacts and/or dependencies

  • options (Hash) (defaults to: {})

    the list of options to pass

Options Hash (options):

  • :status (String) — default: default: 'promoted'

    new build status (any string)

  • :comment (String) — default: default: ''

    an optional comment describing the reason for promotion

  • :user (String) — default: default: +Artifactory.username+

    the user that invoked promotion

  • :dry_run (Boolean) — default: default: +false+

    pretend to do the promotion

  • :copy (Boolean) — default: default: +false+

    whether to copy instead of move

  • :dependencies (Boolean) — default: default: +false+

    whether to move/copy the build’s dependencies

  • :scopes (Array) — default: default: []

    an array of dependency scopes to include when “dependencies” is true

  • :properties (Hash<String, Array<String>>) — default: default: []

    a list of properties to attach to the build’s artifacts

  • :fail_fast (Boolean) — default: default: +true+

    fail and abort the operation upon receiving an error

Returns:

  • (Hash)

    the parsed JSON response from the server



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/artifactory/resources/build.rb', line 174

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

#propertiesObject

Return this object’s properties

Returns:

  • (Object)


96
# File 'lib/artifactory/resources/build.rb', line 96

attribute :properties, {}

#properties=(value) ⇒ Object

Set this object’s properties

Parameters:

  • value (Object)

    the value to set for properties

  • default (Object)

    the default value for this attribute



96
# File 'lib/artifactory/resources/build.rb', line 96

attribute :properties, {}

#properties?Boolean

Determines if the properties value exists and is truthy

Returns:

  • (Boolean)


96
# File 'lib/artifactory/resources/build.rb', line 96

attribute :properties, {}

#saveBoolean

Creates data about a build.

Returns:

  • (Boolean)


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/artifactory/resources/build.rb', line 200

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

#startedObject

Return this object’s started

Returns:

  • (Object)


103
# File 'lib/artifactory/resources/build.rb', line 103

attribute :started, Time.now.utc.iso8601(3)

#started=(value) ⇒ Object

Set this object’s started

Parameters:

  • value (Object)

    the value to set for started

  • default (Object)

    the default value for this attribute



103
# File 'lib/artifactory/resources/build.rb', line 103

attribute :started, Time.now.utc.iso8601(3)

#started?Boolean

Determines if the started value exists and is truthy

Returns:

  • (Boolean)


103
# File 'lib/artifactory/resources/build.rb', line 103

attribute :started, Time.now.utc.iso8601(3)

#typeObject

Return this object’s type

Returns:

  • (Object)


100
# File 'lib/artifactory/resources/build.rb', line 100

attribute :type, 'GENERIC'

#type=(value) ⇒ Object

Set this object’s type

Parameters:

  • value (Object)

    the value to set for type

  • default (Object)

    the default value for this attribute



100
# File 'lib/artifactory/resources/build.rb', line 100

attribute :type, 'GENERIC'

#type?Boolean

Determines if the type value exists and is truthy

Returns:

  • (Boolean)


100
# File 'lib/artifactory/resources/build.rb', line 100

attribute :type, 'GENERIC'

#urlObject

Return this object’s url

Returns:

  • (Object)


106
# File 'lib/artifactory/resources/build.rb', line 106

attribute :url

#url=(value) ⇒ Object

Set this object’s url

Parameters:

  • value (Object)

    the value to set for url

  • default (Object)

    the default value for this attribute



106
# File 'lib/artifactory/resources/build.rb', line 106

attribute :url

#url?Boolean

Determines if the url value exists and is truthy

Returns:

  • (Boolean)


106
# File 'lib/artifactory/resources/build.rb', line 106

attribute :url

#vcs_revisionObject

Return this object’s vcs_revision

Returns:

  • (Object)


107
# File 'lib/artifactory/resources/build.rb', line 107

attribute :vcs_revision

#vcs_revision=(value) ⇒ Object

Set this object’s vcs_revision

Parameters:

  • value (Object)

    the value to set for vcs_revision

  • default (Object)

    the default value for this attribute



107
# File 'lib/artifactory/resources/build.rb', line 107

attribute :vcs_revision

#vcs_revision?Boolean

Determines if the vcs_revision value exists and is truthy

Returns:

  • (Boolean)


107
# File 'lib/artifactory/resources/build.rb', line 107

attribute :vcs_revision

#vcs_urlObject

Return this object’s vcs_url

Returns:

  • (Object)


108
# File 'lib/artifactory/resources/build.rb', line 108

attribute :vcs_url

#vcs_url=(value) ⇒ Object

Set this object’s vcs_url

Parameters:

  • value (Object)

    the value to set for vcs_url

  • default (Object)

    the default value for this attribute



108
# File 'lib/artifactory/resources/build.rb', line 108

attribute :vcs_url

#vcs_url?Boolean

Determines if the vcs_url value exists and is truthy

Returns:

  • (Boolean)


108
# File 'lib/artifactory/resources/build.rb', line 108

attribute :vcs_url

#versionObject

Return this object’s version

Returns:

  • (Object)


97
# File 'lib/artifactory/resources/build.rb', line 97

attribute :version, BUILD_SCHEMA_VERSION

#version=(value) ⇒ Object

Set this object’s version

Parameters:

  • value (Object)

    the value to set for version

  • default (Object)

    the default value for this attribute



97
# File 'lib/artifactory/resources/build.rb', line 97

attribute :version, BUILD_SCHEMA_VERSION

#version?Boolean

Determines if the version value exists and is truthy

Returns:

  • (Boolean)


97
# File 'lib/artifactory/resources/build.rb', line 97

attribute :version, BUILD_SCHEMA_VERSION