TeamCity build status parameter

拜拜、爱过 提交于 2019-12-07 01:57:45

问题


I may be overlooking a built in parameter in TeamCity.. I'm trying to send the build status as a parameter to a console application. The console application is a build step that needs to run even if previous steps have failed. If previous steps failed it will do one thing, and if the previous steps are successful it will do another.

I have the console app set up to take a build status parameter, but I'm not finding a built in build status parameter to use (Success/Failure). Am I missing something easy? How can I access the build status?

Thanks!


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/25068829/teamcity-build-status-parameter

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