Module: TeamCity::Client::BuildTypes

Included in:
TeamCity::Client
Defined in:
lib/teamcity/client/build_types.rb

Overview

Defines methods related to build types (or build configurations)

Instance Method Summary collapse

Instance Method Details

#attach_vcs_root(buildtype_id, vcs_root_id) ⇒ Hashie::Mash

Attach a vcs root to a build type (build configuration_)

Parameters:

  • buildtype_id (String)

    the buildtype id

  • vcs_root_id (String, Numeric)

    id of vcs root

Returns:

  • (Hashie::Mash)

    vcs root object that was attached



127
128
129
130
131
132
133
# File 'lib/teamcity/client/build_types.rb', line 127

def attach_vcs_root(buildtype_id, vcs_root_id)
  payload = { 'vcs-root' => { :id => vcs_root_id } }

  post("buildTypes/#{buildtype_id}/vcs-root-entries", :content_type => :json) do |req|
    req.body = payload.to_json
  end
end

#buildtype(options = {}) ⇒ Hashie::Mash

Get build configuration details

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Hashie::Mash)

    of build configuration details



19
20
21
22
# File 'lib/teamcity/client/build_types.rb', line 19

def buildtype(options={})
  assert_options(options)
  get("buildTypes/#{locator(options)}")
end

#buildtype_agent_requirements(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration agent_requirements

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration agent_requirements



116
# File 'lib/teamcity/client/build_types.rb', line 116

make_method :agent_requirements

#buildtype_artifact_dependencies(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration artifact_dependencies

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration artifact_dependencies



117
# File 'lib/teamcity/client/build_types.rb', line 117

make_method :artifact_dependencies

#buildtype_branches(buildtype_id) ⇒ Array<Hashie::Mash>

Get a listing of vcs branches

Parameters:

  • buildtype_id (String)

Returns:

  • (Array<Hashie::Mash>)


39
40
41
42
43
# File 'lib/teamcity/client/build_types.rb', line 39

def buildtype_branches(buildtype_id)
  path = "buildTypes/#{buildtype_id}/branches"
  response = get(path, :accept => :json, :content_type => :json)
  response.branch
end

#buildtype_features(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration features

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration features



113
# File 'lib/teamcity/client/build_types.rb', line 113

make_method :features

#buildtype_investigations(buildtype_id) ⇒ Array<Hashie::Mash>

Get investigation info for build configuration

Parameters:

  • buildtype_id (String)

    the buildtype id

Returns:

  • (Array<Hashie::Mash>)

    of build investigation info



79
80
81
82
# File 'lib/teamcity/client/build_types.rb', line 79

def buildtype_investigations(buildtype_id)
  response = get("buildTypes/#{buildtype_id}/investigations")
  response['investigation']
end

#buildtype_parameters(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration parameters

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration parameters



69
70
71
72
73
# File 'lib/teamcity/client/build_types.rb', line 69

def buildtype_parameters(options={})
  assert_options(options)
  response = get("buildTypes/#{locator(options)}/parameters")
  response['property']
end

#buildtype_settings(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration settings

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration settings



59
60
61
62
63
# File 'lib/teamcity/client/build_types.rb', line 59

def buildtype_settings(options={})
  assert_options(options)
  response = get("buildTypes/#{locator(options)}/settings")
  response['property']
end

#buildtype_snapshot_dependencies(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration snapshot_dependencies

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration snapshot_dependencies



118
# File 'lib/teamcity/client/build_types.rb', line 118

make_method :snapshot_dependencies

#buildtype_state(options = {}) ⇒ String

Get whether the build is paused or not

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (String)

    ‘true’ or ‘false’ on whether the build is paused



49
50
51
52
53
# File 'lib/teamcity/client/build_types.rb', line 49

def buildtype_state(options={})
  assert_options(options)
  path = "buildTypes/#{locator(options)}/paused"
  get(path, :accept => :text, :content_type => :text)
end

#buildtype_steps(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration steps

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration steps



115
# File 'lib/teamcity/client/build_types.rb', line 115

make_method :steps

#buildtype_template(options = {}) ⇒ Hashie::Mash?

Get template associated with build configuration

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Hashie::Mash, nil)

    of build configuration parameters or nil if



88
89
90
91
92
93
94
95
# File 'lib/teamcity/client/build_types.rb', line 88

def buildtype_template(options={})
  assert_options(options)
  begin
    get("buildTypes/#{locator(options)}/template")
  rescue StandardError => e
    /No template associated/.match(e.to_s) ? nil : raise
  end
end

#buildtype_triggers(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration triggers

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration triggers



114
# File 'lib/teamcity/client/build_types.rb', line 114

make_method :triggers

#buildtype_vcs_root_entries(options = {}) ⇒ Array<Hashie::Mash>

Get build configuration vcs_root_entries

Parameters:

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

    option keys, :id => buildtype_id

Returns:

  • (Array<Hashie::Mash>)

    of build configuration vcs_root_entries



119
# File 'lib/teamcity/client/build_types.rb', line 119

make_method :vcs_root_entries

#buildtypesArray<Hashie::Mash>?

List of build types

Returns:

  • (Array<Hashie::Mash>, nil)

    of buildtypes or nil if no buildtypes exist



10
11
12
13
# File 'lib/teamcity/client/build_types.rb', line 10

def buildtypes
  response = get('buildTypes')
  response['buildType']
end

#create_agent_requirement(buildtype_id, parameter_name, parameter_value, condition) ⇒ Hashie::Mash

Note:

Check the TeamCity UI for supported conditions

Create a buildtype agent requirement (Create)

Examples:

Create a condition where a system property equals something

TeamCity.create_agent_requirement('bt1', 'system.os.name', 'Linux', 'equals')

Parameters:

  • buildtype_id (String)

    the buildtype id

  • parameter_name (String)

    name of the parameter to set

  • parameter_value (String)

    value of the parameter

  • condition (String)

    the condition for which to check against

Returns:

  • (Hashie::Mash)


172
173
174
175
176
177
178
179
180
181
182
# File 'lib/teamcity/client/build_types.rb', line 172

def create_agent_requirement(buildtype_id, parameter_name, parameter_value, condition)
  builder = TeamCity::ElementBuilder.new(:id => parameter_name, :type => condition) do |properties|
    properties['property-name']  = parameter_name
    properties['property-value'] = parameter_value
  end

  path = "buildTypes/#{buildtype_id}/agent-requirements"
  post(path, :accept => :json, :content_type => :json) do |req|
    req.body = builder.to_request_body
  end
end

#create_build_step(buildtype_id, options = {}) {|Hash| ... } ⇒ Hashie::Mash

Create Build Step

Examples:

Create a Maven2 step that executes the target verify

TeamCity.create_build_step(:buildtype_id => 'my-build-type-id', :type => 'Maven', name: 'Unit Tests') do |properties|
  properties['goals'] = 'verify'
  properties['mavenSelection'] = 'mavenSelection:default'
  properties['pomLocation'] = 'pom.xml'
end

Parameters:

  • buildtype_id (String)

    :buildtype_id to create the step under

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

    a customizable set of options

Options Hash (options):

  • :name (String)

    for the step definition (optional)

  • :type (String)

    Type of Build Step: ‘Maven’, ‘Ant’, etc

Yields:

  • (Hash)

    properties to set on the step, view the official documentation for supported properties

Returns:

  • (Hashie::Mash)

    step object that was created



266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/teamcity/client/build_types.rb', line 266

def create_build_step(buildtype_id, options = {}, &block)
  attributes = {
    :type => options.fetch(:type),
    :name => options.fetch(:name) { nil }
  }

  builder = TeamCity::ElementBuilder.new(attributes, &block)

  post("buildTypes/#{buildtype_id}/steps", :content_type => :json) do |req|
    req.body = builder.to_request_body
  end
end

#create_build_trigger(buildtype_id, options = {}) {|Hash| ... } ⇒ Hashie::Mash

Create Build Trigger

Examples:

Create a a VCS build trigger for checkins

TeamCity.create_build_step(:buildtype_id => 'my-build-type-id', :type => 'vcsTrigger', name: 'Every Checkin') do |properties|
  properties['groupCheckkinsByCommitter'] = 'true'
  properties['perCheckinTriggering'] = 'true'
  properties['quietPeriodMode'] = 'DO_NOT_USE'
end

Parameters:

  • buildtype_id (String)

    :buildtype_id to create the trigger under

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

    a customizable set of options

Options Hash (options):

  • :type (String)

    Type of Build Trigger: ‘vcsTrigger’, ‘schedulingTrigger’, etc

Yields:

  • (Hash)

    properties to set on the trigger, view the official documentation for supported properties

Returns:

  • (Hashie::Mash)

    trigger object that was created



292
293
294
295
296
297
298
299
300
301
302
# File 'lib/teamcity/client/build_types.rb', line 292

def create_build_trigger(buildtype_id, options = {}, &block)
  attributes = {
    :type => options.fetch(:type),
  }

  builder = TeamCity::ElementBuilder.new(attributes, &block)

  post("buildTypes/#{buildtype_id}/triggers", :content_type => :json) do |req|
    req.body = builder.to_request_body
  end
end

#create_buildtype(project_id, name) ⇒ Hashie::Mash

Create a Build Configuration

Parameters:

  • project_id (String)

    id of the project you are adding the build configuration

  • name (String)

    name of the buildtype you wish to create

Returns:

  • (Hashie::Mash)

    of build configuration details



29
30
31
32
33
# File 'lib/teamcity/client/build_types.rb', line 29

def create_buildtype(project_id, name)
  post("projects/#{project_id}/buildTypes", :content_type => :text) do |req|
    req.body = name
  end
end

#delete_agent_requirement(buildtype_id, parameter_name) ⇒ nil

Delete an agent requirement for a buildtype

Parameters:

  • buildtype_id (String)

    the buildtype_id

  • parameter_name (String)

    name of the requirement to delete

Returns:

  • (nil)


189
190
191
# File 'lib/teamcity/client/build_types.rb', line 189

def delete_agent_requirement(buildtype_id, parameter_name)
  delete("buildTypes/#{buildtype_id}/agent-requirements/#{parameter_name}")
end

#delete_buildtype(buildtype_id) ⇒ nil

Delete buildtype (build configuration)

Parameters:

  • buildtype_id (String)

    the id of the buildtype

Returns:

  • (nil)


234
235
236
# File 'lib/teamcity/client/build_types.rb', line 234

def delete_buildtype(buildtype_id)
  delete("buildTypes/#{buildtype_id}")
end

#delete_buildtype_parameter(buildtype_id, parameter_name) ⇒ nil

Delete a buildtype parameter

Parameters:

  • buildtype_id (String)

    the buildtype id

  • parameter_name (String)

    name of the parameter to delete

Returns:

  • (nil)


154
155
156
157
158
# File 'lib/teamcity/client/build_types.rb', line 154

def delete_buildtype_parameter(buildtype_id, parameter_name)
  path = "buildTypes/#{buildtype_id}/parameters/#{parameter_name}"
  delete(path, :accept => :text, :content_type => :text)
  return nil
end

#set_build_step_field(buildtype_id, step_id, field_name, field_value) ⇒ nil

Set build step field

Parameters:

  • buildtype_id (String)

    the id of the buildtype

  • step_id (String)

    the id of the build step

  • field_name (String)

    the name of the field to set

  • field_value (String)

    the value to set the field name to

Returns:

  • (nil)


245
246
247
248
249
250
# File 'lib/teamcity/client/build_types.rb', line 245

def set_build_step_field(buildtype_id, step_id, field_name, field_value)
  path = "buildTypes/#{buildtype_id}/steps/#{step_id}/#{field_name}"
  put(path, :accept => :text, :content_type => :text) do |req|
    req.body = field_value
  end
end

#set_buildtype_field(buildtype_id, field_name, field_value) ⇒ Object

Set a buildtype field

Examples:

Change buildtype name

TeamCity.set_buildtype_field('bt3', 'name', 'new-name')

Set buildtype description

TeamCity.set_buildtype_field('bt3', 'description', 'new-description')

Pause/Unpause a buildtype

Teamcity.set_buildtype_field('buildtype', 'paused', 'true|false')

Parameters:

  • buidltype_id (String)

    the buildtype id

  • field_name (String)

    the field name

  • field_value (String)

    the value to set the field to



206
207
208
209
210
211
# File 'lib/teamcity/client/build_types.rb', line 206

def set_buildtype_field(buildtype_id, field_name, field_value)
  path = "buildTypes/#{buildtype_id}/#{field_name}"
  put(path, :accept => :text, :content_type => :text) do |req|
    req.body = field_value
  end
end

#set_buildtype_parameter(buildtype_id, parameter_name, parameter_value) ⇒ Object

Set a buildtype parameter (Create or Update)

Parameters:

  • buildtype_id (String)

    the buildtype id

  • parameter_name (String)

    name of the parameter to set

  • parameter_value (String)

    value of the parameter



142
143
144
145
146
147
# File 'lib/teamcity/client/build_types.rb', line 142

def set_buildtype_parameter(buildtype_id, parameter_name, parameter_value)
  path = "buildTypes/#{buildtype_id}/parameters/#{parameter_name}"
  put(path, :accept => :text, :content_type => :text) do |req|
    req.body = parameter_value
  end
end

#set_buildtype_setting(buildtype_id, setting_name, setting_value) ⇒ Object

Set buildtype settings

Examples:

Cleaning all files between the builds

TeamCity.set_buildtype_setting('bt3', 'cleanBuild', 'true')

Checkout on the server

TeamCity.set_buildtype_setting('bt3', 'checkoutMode', 'ON_SERVER')

Fail the build after 10 Minutes

Teamcity.set_buildtype_setting('bt3', 'executionTimeoutMin', '10')

Parameters:

  • buidltype_id (String)

    the buildtype id

  • setting_name (String)

    the settings name

  • setting_value (String)

    the value to set the settings to



226
227
228
# File 'lib/teamcity/client/build_types.rb', line 226

def set_buildtype_setting(buildtype_id, setting_name, setting_value)
  set_buildtype_field(buildtype_id, "settings/#{setting_name}", setting_value)
end