0

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.

  • 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 Aug 08 '16 at 10:18
  • 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 Aug 08 '16 at 10:29
  • 1
    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. – Matt Aug 08 '16 at 12:09

2 Answers2

2

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

Matt
  • 3,684
  • 1
  • 17
  • 19
  • Guess, I've got to start dealing with REST, I just thought of some variable/parameter or another workaround for this issue. As far as I understood, the good way is to use Powershell script for this things? I will be grateful if, you help me with this one. – Dmytro Bukanov Aug 08 '16 at 13:24
  • I've updated the answer with an implementation. Once the step has run, your TeamCity parameter will be populated with the value for the duration of the build and you can reference it as normal inside subsequent steps i.e. where you are naming your installer output – Matt Aug 08 '16 at 14:15
  • Thanks, it works) Pretty sad that I can't do more than +1 Also, %system...% didn't work, I've added user for this script, but important thing that password should be like this: `$pass = urpass |ConvertTo-SecureString -AsPlainText -Force`, otherwise PSCredential shows overload error – Dmytro Bukanov Aug 09 '16 at 08:31
  • There used to be a bug around %system.teamcity.auth.password% so it depends on the version of TC you're running. I can confirm the script works against build 9.1.6 without any issues, but I'm glad it put you on the right track. – Matt Aug 09 '16 at 08:54
1

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']"
AxelWass
  • 1,321
  • 12
  • 21