Solved

How to use Rest APi to get Teamcity information

Posted on 2014-03-14
3
1,262 Views
Last Modified: 2014-03-20
I am relatively new to Teamcity. I have created a project and configurations, run builds, etc. For a release, I need to create a report to send out, (for one project), I want to list all the configurations, the last build #, and the url for each configuration, to a report. What is the best way of doing this (they use Ant and Python here). Can someone give me (or point me to), an example of this (using the Rest API?). How to get the info, and then how to export this to a report\txt file. Basically, I am looking for the script example to do this.  Please do not just point me to the teamcity rest documentation, I don't understand how to apply it in a script file.  Do I need addition tools like curl, etc.?
0
Comment
Question by:eelou
3 Comments
 
LVL 9

Expert Comment

by:techtonik
ID: 39929472
I am not familiar with Teamcity REST API, but in generic way REST API is just a bunch of URLs. You do GET or POST requests to these URLs to query info from them (URL itself specifies the item) and save result to variable.

The best library to do HTTP requests in Python is http://docs.python-requests.org/en/latest/
0
 
LVL 15

Accepted Solution

by:
Walter Ritzel earned 500 total points
ID: 39935209
0
 

Author Comment

by:eelou
ID: 39942305
The links above were helpful.  The problem that I ran into was the user\password.  This is what we came up with...

#!/usr/bin/python
# coding=utf8

import urllib.request
import base64
import xml.etree.ElementTree as ET

base64auth = base64.b64encode("{0}:{1}".format("username", "password").encode("ascii")).decode("ascii").replace("\n","")

#put real ip address below
url = "http://111.11.11.111/httpAuth/app/rest/projects/project111/buildTypes"
request = urllib.request.Request(url)
request.add_header("Authorization", "Basic {0}".format(base64auth))
response = urllib.request.urlopen(request)
Configurations = ET.fromstring(response.read().decode('utf-8'))

for config in Configurations.findall('buildType'):
      print ('{0},{1}'.format(config.attrib['name'],"  " + config.attrib['id']))
0

Featured Post

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now