TeamCity build status parameter

萝らか妹 提交于 2019-12-05 06:49:46

I've had to do a similar thing in the past and didn't manage to find a built in property that I could inject to pass the status.

In the end I used service messages in a previous build step to pass parameters into the subsequent step - printing out a message like ##teamcity[setParameter name='build.state' value='ok'] can be used to create a build property to thread state from one step to another.

I've seen someone take an approach of using the TeamCity REST API to query the status of the running build from a build step, but the prior approach was simple enough for me.

I ended up using the solution found here:

http://mnaoumov.wordpress.com/2013/01/31/get-teamcity-build-status-from-powershell/

I just created the same logic in C# in my console app to get the build status.

I have tried the code in the link in the answer by user2097151, but it did not work at first. So I modified it. I will post the modifications here:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;

$buildId = "%teamcity.build.id%"
function TeamCityBuildStatus
{
    param
    (
        [string] $ServerUrl,
        [string] $UserName,
        [string] $Password,
        [string] $BuildId
    )

        $client = New-Object System.Net.WebClient

        $pair = "$($UserName):$Password"
        $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
        $client.Headers.Add("Authorization", "Basic $encodedCreds")

        $url = "https://$ServerUrl/httpAuth/app/rest/builds/$buildId/status"

        $status = $client.DownloadString($url)

        return $status -eq "SUCCESS"
}

$status = TeamCityBuildStatus -ServerUrl $teamcityUrl -UserName $teamcityUser -Password $teamcityPass -BuildId $buildId

This solution dose not relay in this being the last build.

The way I send the credentials I found it in this thread. And the TLS version change I found it in this thread.

Hope it helps someone.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!