Teamcity doesn't detect msbuild nor nUnit failures when executed from powershell

1.2k views Asked by At

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

2

There are 2 answers

2
sylvanaar On BEST ANSWER

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']
1
ArtificialGold On

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" }
    }
}