Get TeamCity build status from PowerShell

TeamCity has REST api, so it is pretty easy to get the build status from PowerShell.

The function implemented with earliest failure detection: build will be considered as broken if either it has be completed as broken or currently running is broken.

function Test-TeamCityBuildStatus
        [string] $ServerUrl,
        [string] $UserName,
        [string] $Password,
        [string] $BuildTypeId

        $client = New-Object System.Net.WebClient
        $client.Credentials = New-Object System.Net.NetworkCredential $UserName, $Password

        $url = "$ServerUrl/httpAuth/app/rest/buildTypes/id:$BuildTypeId/builds/canceled:false/status"

        $status = $client.DownloadString($url)

        if ($status -ne "SUCCESS")
            return $false
            $url = "$ServerUrl/httpAuth/app/rest/buildTypes/id:$buildTypeId/builds/canceled:false,running:any/status"
            $status = $client.DownloadString($url)
            $status -eq "SUCCESS"
        return $null

About mnaoumov

Senior .NET Developer in Readify
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s