0
votes

I've got Teamcity running build, which has artifact output of *.msi installer, I need to mark successfull and failed tests builds, something like

<filename>_<build_status>.msi

I've set TC to build installer even if some tests are failed, in order to send it our tester. So the thing is to recieve build status from TeamCity environment, without using REST.

2
Why not split the build and the tests into separate build configurations? Either way, you can configure individual steps inside a build configuration to always run, even if the previous step failed.Lasse V. Karlsen
I've got separate 'test' build configuration, but I also need to run tests before making another build with installer output, the thing is I can't retrieve build status neither from environment variables nor from parameters. REST is not the best solution, so I need alternatives.Dmytro Bukanov
Unless you want to interogate system files (like the log and look for some regex), I think REST is you only viable solution here. It works and you'll be able to get the status in a very few lines of code.Evolve Software Ltd

2 Answers

2
votes

I realise that you said you didn't want to use REST, but all you need to do is perform a GET request for this URL, substituting your build configuration id. IMO this is the simplest approach (provided the installer build config is a separate build)

/httpAuth/app/rest/builds/buildType:Installer_Build/status

If you need help implementing this then let me know.

IMPLEMENTATION

1) Add a parameter that you want to be set as the output from the GET request

2) Add a PowerShell step and run the code as source - Get Build Status Gist

3) Update the relevant parameters highlighted below to match your settings

enter image description here

Hope this helps

1
votes

This answer I used for an other SO question dose apply for this one too.

It works on TeamCity Enterprise 2017.1.2 (build 46812)

Here you can find my original answer.

[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
Write-Host "##teamcity[setParameter name='Status' value='$status']"