Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit 477674c

Browse files
committed
Added TeamCity service.
1 parent 4a1152f commit 477674c

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ Thanks to the following people for making this possible
4848
- Matias Korhonen
4949
- Stian Grytøyr
5050
- Nils Adermann
51+
- Brian R. Jackson

docs/github_payload

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
{
44
"data" => {
5-
"subscribers" => "" #CSV list
5+
"base_url" => "http://teamcity.example.com/",
6+
"build_type_id" => "bt123",
7+
"username" => "DOMAIN\\user",
8+
"password" => "MyP@ssw0rD"
69
},
710

811
"payload" => {

docs/teamcity

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
TeamCity
2+
=======
3+
4+
TeamCity is a continuous integration server that automates the building and testing of your software.
5+
The github TeamCity service can be used to trigger builds after code has been pushed to your git repository.
6+
7+
Install Notes
8+
-------------
9+
10+
1. Your TeamCity server must be accessible from the internet.
11+
12+
2. "base_url" is the URL to your TeamCity server
13+
Example: https://teamcity.example.com/ or http://teamcity.example.com/teamcity/
14+
15+
3. "build_type_id" is the identifier of the build configuration you want to trigger
16+
Example: "bt123", which can be found in URL of the build configuration page ("...viewType.html?buildTypeId=bt123&...")
17+
18+
4. "username" and "password" - username and password of a TeamCity user that can
19+
trigger a manual build of the TeamCity build configuration defined in "build_type_id"
20+
21+
Developer Notes
22+
---------------
23+
24+
data
25+
- base_url
26+
- build_type_id
27+
- username
28+
- password
29+
30+
payload
31+
- refer to docs/github_payload

services/teamcity.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module TeamCity
2+
class Remote
3+
4+
def initialize(data = {})
5+
@base_url, @build_type_id, @username, @password = data['base_url'], data['build_type_id'], data['username'], data['password']
6+
instance_variables.each{|var| raise GitHub::ServiceConfigurationError.new("Missing configuration: #{var}") if instance_variable_get(var).to_s.empty? }
7+
@uri = URI.parse(@base_url.gsub(/\/$/, ''))
8+
@conn = Net::HTTP.new(@uri.host, @uri.port)
9+
@conn.use_ssl = @uri.scheme.eql?("https")
10+
@conn.verify_mode = OpenSSL::SSL::VERIFY_NONE
11+
end
12+
13+
def trigger_build
14+
@conn.start do |http|
15+
req = Net::HTTP::Get.new('/httpAuth/action.html?add2Queue=' + CGI.escape(@build_type_id))
16+
req.basic_auth @username, @password
17+
resp = http.request(req)
18+
if resp
19+
# TeamCity REST API never returns a body
20+
# but at least raise an HTTP error if response.code is not 2xx
21+
resp.value
22+
end
23+
end
24+
end
25+
26+
end
27+
end
28+
29+
service :teamcity do |data, payload|
30+
begin
31+
TeamCity::Remote.new(data).trigger_build
32+
rescue SocketError => e
33+
raise GitHub::ServiceConfigurationError.new("Invalid TeamCity host name") if e.to_s =~ /getaddrinfo: Name or service not known/
34+
raise
35+
rescue => e
36+
case e.to_s
37+
when /\((?:403|401|422)\)/ then raise GitHub::ServiceConfigurationError, "Invalid credentials"
38+
when /\((?:404|301|302)\)/ then raise GitHub::ServiceConfigurationError, "Invalid TeamCity URL"
39+
else raise
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)