-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteamcity.py
63 lines (49 loc) · 1.94 KB
/
teamcity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import slumber
import requests
class Session:
def __init__(self, url, user, password):
self.api_session = requests.session()
self.api_session.headers['Accept'] = 'application/json'
self.api_session.headers['Content-Type'] = 'application/json'
self.api_session.headers['Origin'] = url
self.auth = requests.auth.HTTPBasicAuth(user, password)
self.api = slumber.API(url, session = self.api_session, auth = self.auth)
def locator_to_string(self, locator):
return ','.join(['%s:%s' % (key, str(value)) for key, value in locator.iteritems()])
def trigger(self, build_conf, properties = {}, personal = False, change = None, branch = None):
data = {
'buildType': {
'id': build_conf
},
'personal': personal
}
if branch:
data['branchName'] = branch
if properties:
data['properties'] = {
'property': [
{
'name': key,
'value': value
} for key, value in properties.iteritems()
]
}
if change is not None:
data['lastChanges'] = {
'change': [
{ 'id': change }
]
}
response = self.api.buildQueue.post(data)
return response
def get_change_id(self, locator):
resource = getattr(self.api.builds, self.locator_to_string(locator)).get()
return resource['lastChanges']['change'][0]['id']
def get_url(self, locator):
resource = getattr(self.api.builds, self.locator_to_string(locator)).get()
return resource['webUrl']
def add_tag(self, locator, tag):
payload = { 'count': 1, 'tag': [ { 'name': tag } ] }
getattr(self.api.builds, self.locator_to_string(locator)).tags.post(payload)