1

I have written a build script using psake which I run in Teamcity.

I have Teamcity 6.0, so I run psake from a .cmd, but I don't think that changes anything.

Everything is working fine, but I have two problems.

  1. Nunit isn't communicating with Teamcity so when a test fails, Teamcity says everything is ok.

  2. MsBuild behaves the same. Even though the build fails, Teamcity reports success.

I would like to know how get Teamcity to detect these failures.

Here is my example script: https://github.com/MikeEast/BuildTests/blob/master/build/build.ps1

Mikael Östberg
  • 16,982
  • 6
  • 61
  • 79

2 Answers2

3

You will probably need to notify Teamcity yourself via its simple but elegant build status notification system.

For example, you could output the following message to stdout during your powershell script.

##teamcity[buildStatus status='FAILURE' text='Some error message']
sylvanaar
  • 8,096
  • 37
  • 59
  • 1
    And, lucky for you, TeamCity just [published a lib](http://nuget.org/List/Packages/TeamCity.ServiceMessages) for creating those messages! – Anthony Mastrean Oct 23 '11 at 03:18
  • It works, but I was hoping for some magic stuff. Like mspec.exe has a `--teamcity` switch that produces this. I had hoped that the TeamCity Nunit testrunner had the same thing somehow. – Mikael Östberg Oct 24 '11 at 10:54
2

The way I have got TeamCity working (with TeamCity version 6.5.4 I must add) is to use the TeamCity module that is provided in the psake download.

Add this to your script:

...
Import-Module "$build_dir\psake\teamcity.psm1"

#Tasks here
...
Remove-Module teamcity

#End Of File

I have a build folder that I have put the module in so that all my builds can access it.

Then it worked out of the box.

I am not using the built in NUnit runner though, I have also put the NUNit console in my build folder and then call that with each UnitTest assembly:

Task Test -depends Build {
    $testAssemblies = (get-childitem $base_dir -r -i "*UnitTests.dll" -exclude "*.config" -Name | Select-string "bin")
    foreach($test_asm_name in $testAssemblies) {
        $full_test_assembly_name = "$base_dir\$test_asm_name"
        Exec { invoke-expression "$nunitconsole_path $full_test_assembly_name" }
    }
}
ArtificialGold
  • 825
  • 5
  • 14
  • We are executing xunit like this: exec { & "$lib_dir\xunit\xunit.console.clr4.exe" "$($p.BuildDir)\$($p.Name).dll" /nunit "$($p.BuildDir)\results.xml"; } and it works great. However, the build always succeeds, when it should fail when there is a test issue. – Blake Niemyjski Dec 18 '13 at 19:12