Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use Rest APi to get Teamcity information

Posted on 2014-03-14
3
Medium Priority
?
1,548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 16

Accepted Solution

by:
Walter Ritzel earned 1500 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

730 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