Module: TeamCity::Client::Projects

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

Overview

Defines methods related to projects

Instance Method Summary collapse

Instance Method Details

#copy_project(source_project_id, target_project_name, options = {}) ⇒ Hashie::Mash

Copy another project

Parameters:

  • source_project_id (String)

    id of the project you wish to copy

  • target_project_name (String)

    name of the project you want to create

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

    copy project options

Options Hash (options):

  • :copyAllAssociatedSettings (Boolean)

    copy all associated settings

Returns:

  • (Hashie::Mash)

    project details


75
76
77
78
79
80
81
82
83
84
85
# File 'lib/teamcity/client/projects.rb', line 75

def copy_project(source_project_id, target_project_name, options={})
  attributes = {
    :name => target_project_name
  }

  payload = { 'sourceProject' => { locator: source_project_id } }.merge(attributes)

  post("projects", :content_type => :json, :accept => :json) do |req|
    req.body = payload.to_json
  end
end

#create_project(name) ⇒ Hashie::Mash

Create an empty project

Parameters:

  • name (String)

    Name of the project

Returns:

  • (Hashie::Mash)

    project details


60
61
62
63
64
# File 'lib/teamcity/client/projects.rb', line 60

def create_project(name)
  post("projects", :content_type => :text) do |req|
    req.body = name
  end
end

#delete_project(project_id) ⇒ nil

Delete a project

Parameters:

  • project_id (String)

    the id of the project

Returns:

  • (nil)

91
92
93
# File 'lib/teamcity/client/projects.rb', line 91

def delete_project(project_id)
  delete("projects/#{project_id}")
end

#delete_project_parameter(project_id, parameter_name) ⇒ nil

Delete a project parameter

Parameters:

  • project_id (String)

    the project id

  • parameter_name (String)

    name of the parameter to delete

Returns:

  • (nil)

100
101
102
103
104
# File 'lib/teamcity/client/projects.rb', line 100

def delete_project_parameter(project_id, parameter_name)
  path = "projects/#{project_id}/parameters/#{parameter_name}"
  delete(path, :accept => :text)
  return nil
end

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

Get parent project

Parameters:

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

    The options hash,

Returns:

  • (Hashie::Mash)

    of the parent project details

REST API VERSION:

  • >= 8.0


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

def parent_project(options={})
  assert_options(options)
  response = get("projects/#{locator(options)}/parentProject")
  return nil if response['id'] == '_Root'
  response
end

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

Get project details

Parameters:

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

    The options hash,

Options Hash (options):

  • :id (String)

    the project id

Returns:

  • (Hashie::Mash)

    of project details


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

def project(options={})
  assert_options(options)
  get("projects/#{locator(options)}")
end

#project_buildtypes(options = {}) ⇒ Array<Hashie::Mash> of build types (an empty array will be returne if none exist)

List of Build Configurations of a project

Parameters:

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

    The options hash,

Returns:

  • (Array<Hashie::Mash> of build types (an empty array will be returne if none exist))

    Array<Hashie::Mash> of build types (an empty array will be returne if none exist)


28
29
30
31
32
# File 'lib/teamcity/client/projects.rb', line 28

def project_buildtypes(options={})
  assert_options(options)
  response = get("projects/#{locator(options)}/buildTypes")
  response['buildType']
end

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

List of parameters defined on a project

Parameters:

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

    The options hash,

Returns:

  • (Array<Hashie::Mash>)

    of parameters (empty if none are defined)


38
39
40
41
42
# File 'lib/teamcity/client/projects.rb', line 38

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

#projectsArray<Hashie::Mash>?

List of projects

Returns:

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

    of projects or nil if no projects exist


9
10
11
12
# File 'lib/teamcity/client/projects.rb', line 9

def projects
  response = get('projects')
  response['project']
end

#set_parent_project(project_id, parent_project_id) ⇒ Hashie::Mash

Set a parent for a given project

Examples:

Set project1 as parent for project2

TeamCity.set_parent_project('project2', 'project1')

Parameters:

  • project_id (String)

    the project id

  • parent_project_id (String)

    the parent project id

Returns:

  • (Hashie::Mash)

    of child project details

REST API VERSION:

  • >= 8.0


149
150
151
152
153
154
155
156
# File 'lib/teamcity/client/projects.rb', line 149

def set_parent_project(project_id, parent_project_id)
  path = "projects/#{project_id}/parentProject"
  payload = { :id => parent_project_id }

  put(path, :content_type => :json, :accept => :json) do |req|
    req.body = payload.to_json
  end
end

#set_project_field(project_id, field_name, field_value) ⇒ String

Set a project field

Examples:

Set a projects name

TeamCity.set_project_field('project1', 'name', 'new-name')

Set a projects description

TeamCity.set_project_field('project1', 'description', 'new-description')

Archive/Unarchive a project

Teamcity.set_project_field('project1', 'archived', 'true|false')

Parameters:

  • project_id (String)

    the project id

  • field_name (String)

    the field name: 'name', 'description', 'archived'

  • field_value (String)

    the value to set the field to

Returns:

  • (String)

    project_field_value that was set


133
134
135
136
137
138
# File 'lib/teamcity/client/projects.rb', line 133

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

#set_project_parameter(project_id, parameter_name, parameter_value) ⇒ String

Set a project parameter (Create or Update)

Parameters:

  • project_id (String)

    the project id

  • parameter_name (String)

    name of the parameter to set

  • parameter_value (String)

    value of the parameter

Returns:

  • (String)

    parameter_value that was set


113
114
115
116
117
118
# File 'lib/teamcity/client/projects.rb', line 113

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