teamcity 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +3 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +83 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +9 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +194 -0
  10. data/Rakefile +1 -0
  11. data/lib/faraday/null_response_body.rb +17 -0
  12. data/lib/teamcity.rb +26 -0
  13. data/lib/teamcity/api.rb +19 -0
  14. data/lib/teamcity/client.rb +16 -0
  15. data/lib/teamcity/client/build_types.rb +305 -0
  16. data/lib/teamcity/client/builds.rb +92 -0
  17. data/lib/teamcity/client/common.rb +23 -0
  18. data/lib/teamcity/client/projects.rb +159 -0
  19. data/lib/teamcity/client/tests.rb +24 -0
  20. data/lib/teamcity/client/vcs_roots.rb +70 -0
  21. data/lib/teamcity/configuration.rb +51 -0
  22. data/lib/teamcity/connection.rb +28 -0
  23. data/lib/teamcity/element_builder.rb +27 -0
  24. data/lib/teamcity/headers.rb +47 -0
  25. data/lib/teamcity/request.rb +35 -0
  26. data/lib/teamcity/version.rb +3 -0
  27. data/spec/cassettes/BuildTypes/DELETE/_delete_agent_requirement/should_delete_the_agent_requirement.yml +83 -0
  28. data/spec/cassettes/BuildTypes/DELETE/_delete_buildtype/should_delete_a_buildtype.yml +40 -0
  29. data/spec/cassettes/BuildTypes/DELETE/_delete_buildtype_parameter/should_delete_a_buildtype_parameter.yml +81 -0
  30. data/spec/cassettes/BuildTypes/GET/_buildtype/should_fetch_the_details_of_a_buildtype_by_id.yml +89 -0
  31. data/spec/cassettes/BuildTypes/GET/_buildtype/should_raise_an_error_if_the_buildtype_does_not_exist.yml +52 -0
  32. data/spec/cassettes/BuildTypes/GET/_buildtype_agent_requirements/should_fetch_the_build_configuration_agent_requirements_for_a_buildtype.yml +46 -0
  33. data/spec/cassettes/BuildTypes/GET/_buildtype_agent_requirements/should_return_an_array.yml +46 -0
  34. data/spec/cassettes/BuildTypes/GET/_buildtype_agent_requirements/should_return_nil_if_there_are_no_agent_requirements_defined.yml +46 -0
  35. data/spec/cassettes/BuildTypes/GET/_buildtype_artifact_dependencies/should_fetch_the_build_configuration_artifact_dependencies_for_a_buildtype.yml +46 -0
  36. data/spec/cassettes/BuildTypes/GET/_buildtype_artifact_dependencies/should_return_an_array.yml +46 -0
  37. data/spec/cassettes/BuildTypes/GET/_buildtype_artifact_dependencies/should_return_nil_if_there_are_no_artifact_dependencies_defined.yml +46 -0
  38. data/spec/cassettes/BuildTypes/GET/_buildtype_branches/should_fetch_vcs_branches_the_vcs_root_is_configured_to_use.yml +46 -0
  39. data/spec/cassettes/BuildTypes/GET/_buildtype_features/should_fetch_the_build_configuration_features_for_a_buildtype.yml +46 -0
  40. data/spec/cassettes/BuildTypes/GET/_buildtype_features/should_return_an_array.yml +46 -0
  41. data/spec/cassettes/BuildTypes/GET/_buildtype_features/should_return_nil_if_there_are_no_features_defined.yml +46 -0
  42. data/spec/cassettes/BuildTypes/GET/_buildtype_investigations/should_get_investigation_details.yml +48 -0
  43. data/spec/cassettes/BuildTypes/GET/_buildtype_investigations/should_return_nil_if_no_one_is_investigating.yml +46 -0
  44. data/spec/cassettes/BuildTypes/GET/_buildtype_parameters/should_fetch_the_build_configuration_parameters_for_a_buildtype.yml +46 -0
  45. data/spec/cassettes/BuildTypes/GET/_buildtype_parameters/should_return_an_array.yml +46 -0
  46. data/spec/cassettes/BuildTypes/GET/_buildtype_parameters/should_return_nil_if_there_are_no_parameters_defined.yml +46 -0
  47. data/spec/cassettes/BuildTypes/GET/_buildtype_settings/should_fetch_the_settings_for_a_given_buildtype.yml +89 -0
  48. data/spec/cassettes/BuildTypes/GET/_buildtype_settings/should_return_an_array.yml +89 -0
  49. data/spec/cassettes/BuildTypes/GET/_buildtype_snapshot_dependencies/should_fetch_the_build_configuration_snapshot_dependencies_for_a_buildtype.yml +46 -0
  50. data/spec/cassettes/BuildTypes/GET/_buildtype_snapshot_dependencies/should_return_an_array.yml +46 -0
  51. data/spec/cassettes/BuildTypes/GET/_buildtype_snapshot_dependencies/should_return_nil_if_there_are_no_snapshot_dependencies_defined.yml +46 -0
  52. data/spec/cassettes/BuildTypes/GET/_buildtype_state/should_fetch_the_state_of_the_buildtype.yml +89 -0
  53. data/spec/cassettes/BuildTypes/GET/_buildtype_steps/should_fetch_the_build_configuration_steps_for_a_buildtype.yml +47 -0
  54. data/spec/cassettes/BuildTypes/GET/_buildtype_steps/should_return_an_array.yml +46 -0
  55. data/spec/cassettes/BuildTypes/GET/_buildtype_steps/should_return_nil_if_there_are_no_steps_defined.yml +46 -0
  56. data/spec/cassettes/BuildTypes/GET/_buildtype_template/should_return_nil_if_the_buildtype_is_not_associated_with_a_template.yml +52 -0
  57. data/spec/cassettes/BuildTypes/GET/_buildtype_template/should_return_the_attributes_of_the_associated_template.yml +46 -0
  58. data/spec/cassettes/BuildTypes/GET/_buildtype_triggers/should_fetch_the_build_configuration_triggers_for_a_buildtype.yml +46 -0
  59. data/spec/cassettes/BuildTypes/GET/_buildtype_triggers/should_return_an_array.yml +46 -0
  60. data/spec/cassettes/BuildTypes/GET/_buildtype_triggers/should_return_nil_if_there_are_no_triggers_defined.yml +46 -0
  61. data/spec/cassettes/BuildTypes/GET/_buildtype_vcs_root_entries/should_fetch_the_build_configuration_vcs_root_entries_for_a_buildtype.yml +47 -0
  62. data/spec/cassettes/BuildTypes/GET/_buildtype_vcs_root_entries/should_return_an_array.yml +47 -0
  63. data/spec/cassettes/BuildTypes/GET/_buildtype_vcs_root_entries/should_return_nil_if_there_are_no_vcs_root_entries_defined.yml +46 -0
  64. data/spec/cassettes/BuildTypes/GET/_buildtypes/should_fetch_all_the_buildtypes.yml +46 -0
  65. data/spec/cassettes/BuildTypes/POST/_attach_vcs_root/should_attach_a_vcs_root_to_a_buildtype.yml +47 -0
  66. data/spec/cassettes/BuildTypes/POST/_create_agent_requirement/should_create_an_agent_requirement_for_a_buildtype.yml +46 -0
  67. data/spec/cassettes/BuildTypes/POST/_create_build_step/should_create_a_build_step_for_a_given_build_type.yml +46 -0
  68. data/spec/cassettes/BuildTypes/POST/_create_build_trigger/should_create_a_build_trigger_for_a_given_build_type.yml +46 -0
  69. data/spec/cassettes/BuildTypes/POST/_create_buildtype/should_create_a_build_type.yml +86 -0
  70. data/spec/cassettes/BuildTypes/PUT/_set_build_step_field/should_disable_a_build_step.yml +44 -0
  71. data/spec/cassettes/BuildTypes/PUT/_set_build_step_field/should_enable_a_build_step.yml +48 -0
  72. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_field/should_pause_a_project.yml +44 -0
  73. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_field/should_set_a_projects_description.yml +44 -0
  74. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_field/should_set_the_buildtype_name.yml +44 -0
  75. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_parameter/should_set_a_buildtype_parameter.yml +44 -0
  76. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_setting/should_set_if_it_should_perform_clean_builds.yml +46 -0
  77. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_setting/should_set_what_is_the_timeout_in_minutes_when_executing_builds.yml +46 -0
  78. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_setting/should_set_where_the_checkout_happens_when_building.yml +46 -0
  79. data/spec/cassettes/Builds/DELETE/_unpin_build/should_unpin_a_build.yml +83 -0
  80. data/spec/cassettes/Builds/GET/_build/should_fetch_the_build_details.yml +91 -0
  81. data/spec/cassettes/Builds/GET/_build/should_raise_an_error_if_the_build_does_not_exist.yml +53 -0
  82. data/spec/cassettes/Builds/GET/_build_artifacts/should_fetch_all_the_artifacts.yml +89 -0
  83. data/spec/cassettes/Builds/GET/_build_pinned_/should_return_false_when_a_build_is_not_pinned.yml +126 -0
  84. data/spec/cassettes/Builds/GET/_build_pinned_/should_return_true_when_a_build_is_pinned.yml +126 -0
  85. data/spec/cassettes/Builds/GET/_build_statistics/should_return_statistics_for_a_build.yml +89 -0
  86. data/spec/cassettes/Builds/GET/_build_tags/should_fetch_the_build_tags.yml +89 -0
  87. data/spec/cassettes/Builds/GET/_build_tags/should_return_an_empty_array_if_there_are_no_build_tags_defined_for_a_build.yml +89 -0
  88. data/spec/cassettes/Builds/GET/_builds/should_allow_you_to_filter_by_multiple_build_locators.yml +46 -0
  89. data/spec/cassettes/Builds/GET/_builds/should_allow_you_to_filter_results_by_build_locators.yml +46 -0
  90. data/spec/cassettes/Builds/GET/_builds/should_fetch_all_the_builds.yml +46 -0
  91. data/spec/cassettes/Builds/GET/_builds/should_return_an_empty_array_if_no_results_are_found.yml +46 -0
  92. data/spec/cassettes/Builds/PUT/_pin_build/should_pin_a_build.yml +83 -0
  93. data/spec/cassettes/Projects/DELETE/_delete_project/should_delete_a_project.yml +82 -0
  94. data/spec/cassettes/Projects/DELETE/_delete_project_parameter/should_delete_a_project_parameter.yml +123 -0
  95. data/spec/cassettes/Projects/GET/_parent_project/should_fetch_the_parent_project_for_a_given_project.yml +46 -0
  96. data/spec/cassettes/Projects/GET/_parent_project/should_return_nil_if_there_is_no_parent_project_for_a_given_project.yml +46 -0
  97. data/spec/cassettes/Projects/GET/_project/should_fetch_a_single_project_by_id.yml +47 -0
  98. data/spec/cassettes/Projects/GET/_project/should_raise_an_error_if_the_project_does_not_exist.yml +52 -0
  99. data/spec/cassettes/Projects/GET/_project_buildtypes/should_fetch_all_the_buildTypes_for_a_project.yml +46 -0
  100. data/spec/cassettes/Projects/GET/_project_buildtypes/should_return_nil_if_the_project_does_not_have_any_build_types.yml +46 -0
  101. data/spec/cassettes/Projects/GET/_project_parameters/should_fetch_all_the_paramters_for_a_given_project.yml +46 -0
  102. data/spec/cassettes/Projects/GET/_project_parameters/should_return_nil_if_there_are_no_parameters_defined_for_a_project.yml +46 -0
  103. data/spec/cassettes/Projects/GET/_projects/should_fetch_projects.yml +46 -0
  104. data/spec/cassettes/Projects/POST/_copy_project/should_copy_a_project.yml +135 -0
  105. data/spec/cassettes/Projects/POST/_create_project/should_create_a_project.yml +45 -0
  106. data/spec/cassettes/Projects/PUT/_set_parent_project/should_set_a_parent_project_for_a_given_project.yml +134 -0
  107. data/spec/cassettes/Projects/PUT/_set_project_field/should_archive_a_project.yml +86 -0
  108. data/spec/cassettes/Projects/PUT/_set_project_field/should_set_a_projects_description.yml +86 -0
  109. data/spec/cassettes/Projects/PUT/_set_project_field/should_set_a_projects_name.yml +86 -0
  110. data/spec/cassettes/Projects/PUT/_set_project_parameter/should_set_a_project_parameter.yml +86 -0
  111. data/spec/cassettes/Tests/GET/_tests/should_allow_you_to_filter_by_test_id.yml +49 -0
  112. data/spec/cassettes/Tests/GET/_tests/should_allow_you_to_filter_results_by_test_count_locator.yml +55 -0
  113. data/spec/cassettes/Tests/GET/_tests/should_fetch_all_the_tests.yml +60 -0
  114. data/spec/cassettes/Tests/GET/_tests/should_return_an_empty_array_if_no_build_is_found.yml +51 -0
  115. data/spec/cassettes/Tests/GET/_tests/should_return_an_empty_array_if_no_test_is_found.yml +51 -0
  116. data/spec/cassettes/Tests/GET/_tests/should_return_an_empty_array_if_not_build_is_given.yml +51 -0
  117. data/spec/cassettes/VCSRoots/GET/_vcs_root_details/should_fetch_the_vcs_root_details.yml +91 -0
  118. data/spec/cassettes/VCSRoots/GET/_vcs_roots/should_fetch_vcs_roots.yml +47 -0
  119. data/spec/cassettes/VCSRoots/POST/_create_vcs_root/should_create_a_git_vcs_root_that_is_shared_with_the_project_and_sub-projects.yml +89 -0
  120. data/spec/cassettes/VCSRoots/POST/_create_vcs_root/should_create_a_subversion_vcs_root_that_is_shared_with_the_project_and_sub-projects.yml +89 -0
  121. data/spec/cassettes/VCSRoots/PUT/_set_vcs_root_field/should_set_a_vcs_modification_check_interval.yml +179 -0
  122. data/spec/faraday/null_response_body_spec.rb +18 -0
  123. data/spec/spec_helper.rb +22 -0
  124. data/spec/support/vcr_setup.rb +9 -0
  125. data/spec/teamcity/api_spec.rb +64 -0
  126. data/spec/teamcity/client/builds_spec.rb +113 -0
  127. data/spec/teamcity/client/buildtypes_spec.rb +308 -0
  128. data/spec/teamcity/client/projects_spec.rb +207 -0
  129. data/spec/teamcity/client/tests_spec.rb +47 -0
  130. data/spec/teamcity/client/vcs_roots_spec.rb +86 -0
  131. data/spec/teamcity/client_spec.rb +14 -0
  132. data/spec/teamcity/element_builder_spec.rb +30 -0
  133. data/spec/teamcity/headers_spec.rb +43 -0
  134. data/spec/teamcity/version_spec.rb +7 -0
  135. data/spec/teamcity_spec.rb +89 -0
  136. data/teamcity.gemspec +26 -0
  137. metadata +344 -0
@@ -0,0 +1,305 @@
1
+ module TeamCity
2
+ class Client
3
+ # Defines methods related to build types (or build configurations)
4
+ module BuildTypes
5
+ # HTTP GET
6
+
7
+ # List of build types
8
+ #
9
+ # @return [Array<Hashie::Mash>, nil] of buildtypes or nil if no buildtypes exist
10
+ def buildtypes
11
+ response = get('buildTypes')
12
+ response['buildType']
13
+ end
14
+
15
+ # Get build configuration details
16
+ #
17
+ # @param options [Hash] option keys, :id => buildtype_id
18
+ # @return [Hashie::Mash] of build configuration details
19
+ def buildtype(options={})
20
+ assert_options(options)
21
+ get("buildTypes/#{locator(options)}")
22
+ end
23
+
24
+ # Create a Build Configuration
25
+ #
26
+ # @param project_id [String] id of the project you are adding the build configuration
27
+ # @param name [String] name of the buildtype you wish to create
28
+ # @return [Hashie::Mash] of build configuration details
29
+ def create_buildtype(project_id, name)
30
+ post("projects/#{project_id}/buildTypes", :content_type => :text) do |req|
31
+ req.body = name
32
+ end
33
+ end
34
+
35
+ # Get a listing of vcs branches
36
+ #
37
+ # @param buildtype_id [String]
38
+ # @return [Array<Hashie::Mash>]
39
+ def buildtype_branches(buildtype_id)
40
+ path = "buildTypes/#{buildtype_id}/branches"
41
+ response = get(path, :accept => :json, :content_type => :json)
42
+ response.branch
43
+ end
44
+
45
+ # Get whether the build is paused or not
46
+ #
47
+ # @param options [Hash] option keys, :id => buildtype_id
48
+ # @return [String] 'true' or 'false' on whether the build is paused
49
+ def buildtype_state(options={})
50
+ assert_options(options)
51
+ path = "buildTypes/#{locator(options)}/paused"
52
+ get(path, :accept => :text, :content_type => :text)
53
+ end
54
+
55
+ # Get build configuration settings
56
+ #
57
+ # @param (see #buildtype)
58
+ # @return [Array<Hashie::Mash>] of build configuration settings
59
+ def buildtype_settings(options={})
60
+ assert_options(options)
61
+ response = get("buildTypes/#{locator(options)}/settings")
62
+ response['property']
63
+ end
64
+
65
+ # Get build configuration parameters
66
+ #
67
+ # @param (see #buildtype)
68
+ # @return [Array<Hashie::Mash>] of build configuration parameters
69
+ def buildtype_parameters(options={})
70
+ assert_options(options)
71
+ response = get("buildTypes/#{locator(options)}/parameters")
72
+ response['property']
73
+ end
74
+
75
+ # Get investigation info for build configuration
76
+ #
77
+ # @param buildtype_id [String] the buildtype id
78
+ # @return [Array<Hashie::Mash>] of build investigation info
79
+ def buildtype_investigations(buildtype_id)
80
+ response = get("buildTypes/#{buildtype_id}/investigations")
81
+ response['investigation']
82
+ end
83
+
84
+ # Get template associated with build configuration
85
+ #
86
+ # @param (see #buildtype)
87
+ # @return [Hashie::Mash, nil] of build configuration parameters or nil if
88
+ def buildtype_template(options={})
89
+ assert_options(options)
90
+ begin
91
+ get("buildTypes/#{locator(options)}/template")
92
+ rescue StandardError => e
93
+ /No template associated/.match(e.to_s) ? nil : raise
94
+ end
95
+ end
96
+
97
+ # @macro [attach] build configuration settings
98
+ # @method buildtype_$1(options = {})
99
+ # Get build configuration $1
100
+ # @param options [Hash] option keys, :id => buildtype_id
101
+ # @return [Array<Hashie::Mash>] of build configuration $1
102
+ def self.make_method(name)
103
+ define_method("buildtype_#{name}".to_sym) do |options|
104
+ name_has_dashes = name.to_s.gsub('_', '-')
105
+ assert_options(options)
106
+ response = get("buildTypes/#{locator(options)}/#{name_has_dashes}", accept: :json)
107
+ response[response.keys.first]
108
+ end
109
+ end
110
+
111
+ private_class_method :make_method
112
+
113
+ make_method :features
114
+ make_method :triggers
115
+ make_method :steps
116
+ make_method :agent_requirements
117
+ make_method :artifact_dependencies
118
+ make_method :snapshot_dependencies
119
+ make_method :vcs_root_entries
120
+
121
+ # Attach a vcs root to a build type (build configuration_)
122
+ #
123
+ #
124
+ # @param buildtype_id [String] the buildtype id
125
+ # @param vcs_root_id [String, Numeric] id of vcs root
126
+ # @return [Hashie::Mash] vcs root object that was attached
127
+ def attach_vcs_root(buildtype_id, vcs_root_id)
128
+ payload = { 'vcs-root' => { :id => vcs_root_id } }
129
+
130
+ post("buildTypes/#{buildtype_id}/vcs-root-entries", :content_type => :json) do |req|
131
+ req.body = payload.to_json
132
+ end
133
+ end
134
+
135
+ # Set a buildtype parameter (Create or Update)
136
+ #
137
+ #
138
+ # @param buildtype_id [String] the buildtype id
139
+ # @param parameter_name [String] name of the parameter to set
140
+ # @param parameter_value [String] value of the parameter
141
+ # @return parameter_value [String] that was set
142
+ def set_buildtype_parameter(buildtype_id, parameter_name, parameter_value)
143
+ path = "buildTypes/#{buildtype_id}/parameters/#{parameter_name}"
144
+ put(path, :accept => :text, :content_type => :text) do |req|
145
+ req.body = parameter_value
146
+ end
147
+ end
148
+
149
+ # Delete a buildtype parameter
150
+ #
151
+ # @param buildtype_id [String] the buildtype id
152
+ # @param parameter_name [String] name of the parameter to delete
153
+ # @return [nil]
154
+ def delete_buildtype_parameter(buildtype_id, parameter_name)
155
+ path = "buildTypes/#{buildtype_id}/parameters/#{parameter_name}"
156
+ delete(path, :accept => :text, :content_type => :text)
157
+ return nil
158
+ end
159
+
160
+ # Create a buildtype agent requirement (Create)
161
+ #
162
+ # @param buildtype_id [String] the buildtype id
163
+ # @param parameter_name [String] name of the parameter to set
164
+ # @param parameter_value [String] value of the parameter
165
+ # @param condition [String] the condition for which to check against
166
+ # @return [Hashie::Mash]
167
+ #
168
+ # @example Create a condition where a system property equals something
169
+ # TeamCity.create_agent_requirement('bt1', 'system.os.name', 'Linux', 'equals')
170
+ #
171
+ # @note Check the TeamCity UI for supported conditions
172
+ def create_agent_requirement(buildtype_id, parameter_name, parameter_value, condition)
173
+ builder = TeamCity::ElementBuilder.new(:id => parameter_name, :type => condition) do |properties|
174
+ properties['property-name'] = parameter_name
175
+ properties['property-value'] = parameter_value
176
+ end
177
+
178
+ path = "buildTypes/#{buildtype_id}/agent-requirements"
179
+ post(path, :accept => :json, :content_type => :json) do |req|
180
+ req.body = builder.to_request_body
181
+ end
182
+ end
183
+
184
+ # Delete an agent requirement for a buildtype
185
+ #
186
+ # @param buildtype_id [String] the buildtype_id
187
+ # @param parameter_name [String] name of the requirement to delete
188
+ # @return [nil]
189
+ def delete_agent_requirement(buildtype_id, parameter_name)
190
+ delete("buildTypes/#{buildtype_id}/agent-requirements/#{parameter_name}")
191
+ end
192
+
193
+ # Set a buildtype field
194
+ #
195
+ # @example Change buildtype name
196
+ # TeamCity.set_buildtype_field('bt3', 'name', 'new-name')
197
+ # @example Set buildtype description
198
+ # TeamCity.set_buildtype_field('bt3', 'description', 'new-description')
199
+ # @example Pause/Unpause a buildtype
200
+ # Teamcity.set_buildtype_field('buildtype', 'paused', 'true|false')
201
+ #
202
+ # @param buidltype_id [String] the buildtype id
203
+ # @param field_name [String] the field name
204
+ # @param field_value [String] the value to set the field to
205
+ # @return field_value [String] value that was set
206
+ def set_buildtype_field(buildtype_id, field_name, field_value)
207
+ path = "buildTypes/#{buildtype_id}/#{field_name}"
208
+ put(path, :accept => :text, :content_type => :text) do |req|
209
+ req.body = field_value
210
+ end
211
+ end
212
+
213
+ # Set buildtype settings
214
+ #
215
+ # @example Cleaning all files between the builds
216
+ # TeamCity.set_buildtype_setting('bt3', 'cleanBuild', 'true')
217
+ # @example Checkout on the server
218
+ # TeamCity.set_buildtype_setting('bt3', 'checkoutMode', 'ON_SERVER')
219
+ # @example Fail the build after 10 Minutes
220
+ # Teamcity.set_buildtype_setting('bt3', 'executionTimeoutMin', '10')
221
+ #
222
+ # @param buidltype_id [String] the buildtype id
223
+ # @param setting_name [String] the settings name
224
+ # @param setting_value [String] the value to set the settings to
225
+ # @return setting_value [String] value that was set
226
+ def set_buildtype_setting(buildtype_id, setting_name, setting_value)
227
+ set_buildtype_field(buildtype_id, "settings/#{setting_name}", setting_value)
228
+ end
229
+
230
+ # Delete buildtype (build configuration)
231
+ #
232
+ # @param buildtype_id [String] the id of the buildtype
233
+ # @return [nil]
234
+ def delete_buildtype(buildtype_id)
235
+ delete("buildTypes/#{buildtype_id}")
236
+ end
237
+
238
+ # Set build step field
239
+ #
240
+ # @param buildtype_id [String] the id of the buildtype
241
+ # @param step_id [String] the id of the build step
242
+ # @param field_name [String] the name of the field to set
243
+ # @param field_value [String] the value to set the field name to
244
+ # @return [nil]
245
+ def set_build_step_field(buildtype_id, step_id, field_name, field_value)
246
+ path = "buildTypes/#{buildtype_id}/steps/#{step_id}/#{field_name}"
247
+ put(path, :accept => :text, :content_type => :text) do |req|
248
+ req.body = field_value
249
+ end
250
+ end
251
+
252
+ # Create Build Step
253
+ #
254
+ # @param buildtype_id [String] :buildtype_id to create the step under
255
+ # @option options [String] :name for the step definition (optional)
256
+ # @option options [String] :type Type of Build Step: 'Maven', 'Ant', etc
257
+ # @yield [Hash] properties to set on the step, view the official documentation for supported properties
258
+ # @return [Hashie::Mash] step object that was created
259
+ #
260
+ # @example Create a Maven2 step that executes the target verify
261
+ # TeamCity.create_build_step(:buildtype_id => 'my-build-type-id', :type => 'Maven', name: 'Unit Tests') do |properties|
262
+ # properties['goals'] = 'verify'
263
+ # properties['mavenSelection'] = 'mavenSelection:default'
264
+ # properties['pomLocation'] = 'pom.xml'
265
+ # end
266
+ def create_build_step(buildtype_id, options = {}, &block)
267
+ attributes = {
268
+ :type => options.fetch(:type),
269
+ :name => options.fetch(:name) { nil }
270
+ }
271
+
272
+ builder = TeamCity::ElementBuilder.new(attributes, &block)
273
+
274
+ post("buildTypes/#{buildtype_id}/steps", :content_type => :json) do |req|
275
+ req.body = builder.to_request_body
276
+ end
277
+ end
278
+
279
+ # Create Build Trigger
280
+ #
281
+ # @param buildtype_id [String] :buildtype_id to create the trigger under
282
+ # @option options [String] :type Type of Build Trigger: 'vcsTrigger', 'schedulingTrigger', etc
283
+ # @yield [Hash] properties to set on the trigger, view the official documentation for supported properties
284
+ # @return [Hashie::Mash] trigger object that was created
285
+ #
286
+ # @example Create a a VCS build trigger for checkins
287
+ # TeamCity.create_build_step(:buildtype_id => 'my-build-type-id', :type => 'vcsTrigger', name: 'Every Checkin') do |properties|
288
+ # properties['groupCheckkinsByCommitter'] = 'true'
289
+ # properties['perCheckinTriggering'] = 'true'
290
+ # properties['quietPeriodMode'] = 'DO_NOT_USE'
291
+ # end
292
+ def create_build_trigger(buildtype_id, options = {}, &block)
293
+ attributes = {
294
+ :type => options.fetch(:type),
295
+ }
296
+
297
+ builder = TeamCity::ElementBuilder.new(attributes, &block)
298
+
299
+ post("buildTypes/#{buildtype_id}/triggers", :content_type => :json) do |req|
300
+ req.body = builder.to_request_body
301
+ end
302
+ end
303
+ end
304
+ end
305
+ end
@@ -0,0 +1,92 @@
1
+ module TeamCity
2
+ class Client
3
+ # Defines methods related to builds
4
+ module Builds
5
+
6
+ # HTTP GET
7
+
8
+ # List of builds
9
+ #
10
+ # @param options [Hash] list of build locators to filter build results on
11
+ # @return [Array<Hashie::Mash>] of builds (empty array if no builds exist)
12
+ def builds(options={})
13
+ url_params = options.empty? ? '' : "?locator=#{locator(options)}"
14
+ response = get("builds#{url_params}")
15
+ response.build
16
+ end
17
+
18
+ # Get build details
19
+ #
20
+ # @param options [Hash] option keys, :id => build_id
21
+ # @return [Hashie::Mash] of build details
22
+ def build(options={})
23
+ assert_options(options)
24
+ get("builds/#{locator(options)}")
25
+ end
26
+
27
+ # Get the build tags
28
+ #
29
+ # @param options [Hash] option keys, :id => build_id
30
+ # @return [Array<Hashie::Mash>] or empty array if no tags exist
31
+ def build_tags(options={})
32
+ assert_options(options)
33
+ response = get("builds/#{locator(options)}/tags")
34
+ response.fetch(:tag)
35
+ end
36
+
37
+ # Get build statistics
38
+ #
39
+ # @param build_id [String]
40
+ # @return [Array<Hashie::Mash>]
41
+ def build_statistics(build_id)
42
+ response = get("builds/#{build_id}/statistics")
43
+ response['property']
44
+ end
45
+
46
+ # Tells you whether or not a build is pinned
47
+ #
48
+ # @param id [String] build to check if it is pinned
49
+ # @return [Boolean] whether the build is pinned or not
50
+ def build_pinned?(id)
51
+ path = "builds/#{id}/pin"
52
+ response = get(path, :accept => :text, :content_type => :text)
53
+ response == 'true'
54
+ end
55
+
56
+ # Get build artifacts
57
+ #
58
+ # @param build_id [String]
59
+ # @return [Array<Hashie::Mash>]
60
+ def build_artifacts(build_id)
61
+ response = get("builds/#{build_id}/artifacts")
62
+ response['files']
63
+ end
64
+
65
+ # HTTP PUT
66
+
67
+ # Pin a build
68
+ #
69
+ # @param id [String] build to pin
70
+ # @param comment [String] provide a comment to the pin
71
+ # @return [nil]
72
+ def pin_build(id, comment='')
73
+ path = "builds/#{id}/pin"
74
+ put(path, :accept => :text, :content_type => :text) do |req|
75
+ req.body = comment
76
+ end
77
+ return nil
78
+ end
79
+
80
+ # HTTP DELETE
81
+
82
+ # Unpin a build
83
+ #
84
+ # @param id [String] build to unpin
85
+ # @return [nil]
86
+ def unpin_build(id)
87
+ path = "builds/#{id}/pin"
88
+ delete(path, :content_type => :text)
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,23 @@
1
+ module TeamCity
2
+ class Client
3
+ # Defines some common methods shared across the other
4
+ # teamcity api modules
5
+ module Common
6
+
7
+ private
8
+
9
+ def assert_options(options)
10
+ !options[:id] and raise ArgumentError, "Must provide an id", caller
11
+ end
12
+
13
+ # Take a list of locators to search on multiple criterias
14
+ #
15
+ def locator(options={})
16
+ options.inject([]) do |locators, locator|
17
+ key, value = locator
18
+ locators << "#{key}:#{value}"
19
+ end.join(',')
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,159 @@
1
+ module TeamCity
2
+ class Client
3
+ # Defines methods related to projects
4
+ module Projects
5
+
6
+ # List of projects
7
+ #
8
+ # @return [Array<Hashie::Mash>, nil] of projects or nil if no projects exist
9
+ def projects
10
+ response = get('projects')
11
+ response['project']
12
+ end
13
+
14
+ # Get project details
15
+ #
16
+ # @param options [Hash] The options hash,
17
+ # @option options [String] :id the project id
18
+ # @return [Hashie::Mash] of project details
19
+ def project(options={})
20
+ assert_options(options)
21
+ get("projects/#{locator(options)}")
22
+ end
23
+
24
+ # List of Build Configurations of a project
25
+ #
26
+ # @param (see #project)
27
+ # @return [Array<Hashie::Mash> of build types (an empty array will be returne if none exist)
28
+ def project_buildtypes(options={})
29
+ assert_options(options)
30
+ response = get("projects/#{locator(options)}/buildTypes")
31
+ response['buildType']
32
+ end
33
+
34
+ # List of parameters defined on a project
35
+ #
36
+ # @param (see #project)
37
+ # @return [Array<Hashie::Mash>] of parameters (empty if none are defined)
38
+ def project_parameters(options={})
39
+ assert_options(options)
40
+ response = get("projects/#{locator(options)}/parameters")
41
+ response['property']
42
+ end
43
+
44
+ # Get parent project
45
+ #
46
+ # @param (see #project)
47
+ # @return [Hashie::Mash] of the parent project details
48
+ # @rest_api_version >= 8.0
49
+ def parent_project(options={})
50
+ assert_options(options)
51
+ response = get("projects/#{locator(options)}/parentProject")
52
+ return nil if response['id'] == '_Root'
53
+ response
54
+ end
55
+
56
+ # Create an empty project
57
+ #
58
+ # @param name [String] Name of the project
59
+ # @return [Hashie::Mash] project details
60
+ def create_project(name)
61
+ post("projects", :content_type => :text) do |req|
62
+ req.body = name
63
+ end
64
+ end
65
+
66
+ # Copy another project
67
+ #
68
+ # @param source_project_id [String] id of the project you wish to copy
69
+ # @param target_project_name [String] name of the project you want to create
70
+ # @param options [Hash] copy project options
71
+ # @option options [Boolean] :copyAllAssociatedSettings copy all associated settings
72
+ # @options options [String] :parentProject used to define the parent project to create this project under (root will be use by default)
73
+ # @options options [String] :id to use for the new project
74
+ # @return [Hashie::Mash] project details
75
+ def copy_project(source_project_id, target_project_name, options={})
76
+ attributes = {
77
+ :name => target_project_name
78
+ }
79
+
80
+ payload = { 'sourceProject' => { locator: source_project_id } }.merge(attributes)
81
+
82
+ post("projects", :content_type => :json, :accept => :json) do |req|
83
+ req.body = payload.to_json
84
+ end
85
+ end
86
+
87
+ # Delete a project
88
+ #
89
+ # @param project_id [String] the id of the project
90
+ # @return [nil]
91
+ def delete_project(project_id)
92
+ delete("projects/#{project_id}")
93
+ end
94
+
95
+ # Delete a project parameter
96
+ #
97
+ # @param project_id [String] the project id
98
+ # @param parameter_name [String] name of the parameter to delete
99
+ # @return [nil]
100
+ def delete_project_parameter(project_id, parameter_name)
101
+ path = "projects/#{project_id}/parameters/#{parameter_name}"
102
+ delete(path, :accept => :text)
103
+ return nil
104
+ end
105
+
106
+ # Set a project parameter (Create or Update)
107
+ #
108
+ #
109
+ # @param project_id [String] the project id
110
+ # @param parameter_name [String] name of the parameter to set
111
+ # @param parameter_value [String] value of the parameter
112
+ # @return [String] parameter_value that was set
113
+ def set_project_parameter(project_id, parameter_name, parameter_value)
114
+ path = "projects/#{project_id}/parameters/#{parameter_name}"
115
+ put(path, :content_type => :text, :accept => :text) do |req|
116
+ req.body = parameter_value
117
+ end
118
+ end
119
+
120
+ # Set a project field
121
+ #
122
+ # @example Set a projects name
123
+ # TeamCity.set_project_field('project1', 'name', 'new-name')
124
+ # @example Set a projects description
125
+ # TeamCity.set_project_field('project1', 'description', 'new-description')
126
+ # @example Archive/Unarchive a project
127
+ # Teamcity.set_project_field('project1', 'archived', 'true|false')
128
+ #
129
+ # @param project_id [String] the project id
130
+ # @param field_name [String] the field name: 'name', 'description', 'archived'
131
+ # @param field_value [String] the value to set the field to
132
+ # @return [String] project_field_value that was set
133
+ def set_project_field(project_id, field_name, field_value)
134
+ path = "projects/#{project_id}/#{field_name}"
135
+ put(path, :content_type => :text, :accept => :text) do |req|
136
+ req.body = field_value
137
+ end
138
+ end
139
+
140
+ # Set a parent for a given project
141
+ #
142
+ # @example Set project1 as parent for project2
143
+ # TeamCity.set_parent_project('project2', 'project1')
144
+ #
145
+ # @param project_id [String] the project id
146
+ # @param parent_project_id [String] the parent project id
147
+ # @return [Hashie::Mash] of child project details
148
+ # @rest_api_version >= 8.0
149
+ def set_parent_project(project_id, parent_project_id)
150
+ path = "projects/#{project_id}/parentProject"
151
+ payload = { :id => parent_project_id }
152
+
153
+ put(path, :content_type => :json, :accept => :json) do |req|
154
+ req.body = payload.to_json
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end