-
Notifications
You must be signed in to change notification settings - Fork 2
/
tfs.py
30 lines (22 loc) · 984 Bytes
/
tfs.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
#!/usr/bin/env python
import requests
from requests_ntlm import HttpNtlmAuth
import simplejson as json
import getpass
TFS_URL = "" # Your TFS URL e.x. https://tfs.yourCompany.com
TFS_TEAM_PROJECT_COLLECTION = "" # Your TFS Collection e.g. DefaultCollection
TFS_TEAM_PROJECT = "" # Your TFS Project e.g. Products
apiForQueuedBuilds = '_api/_build/queuedBuilds'
def getResponse(url, username, password):
response = requests.get(url, auth=HttpNtlmAuth(username, password))
jsonResponse = json.loads(response.text)
return jsonResponse["__wrappedArray"]
def getFullTFSURL():
return '/'.join([TFS_URL,TFS_TEAM_PROJECT_COLLECTION,TFS_TEAM_PROJECT])
def getQueuedBuilds(username, password=''):
fullQueuedBuildsAPI = '/'.join([getFullTFSURL(), apiForQueuedBuilds])
fullQueuedBuildsAPI += "?__v=1&status=63"
if password == '':
password = getpass.getpass("Please enter your password: ")
builds = getResponse(fullQueuedBuildsAPI, username, password)
return builds