0

I have a small powershell task that runs all my unittests using Gallio and teamcity imports the report, but does not fail the build step and does not show the number of tests that failed or passed.

So how do I get teamcity to fail the build based on the tests in the report and how do I get it to show the number of tests passed, ignored and failed in the status.

Add-PSSnapIn Gallio
$fileList = Get-ChildItem ./source/ -filter *.Unittests.dll -Recurse | where { $_.FullName -like "*\bin\*" } | %{$_.FullName}
Run-Gallio -Files $fileList -ReportTypes XML -ReportNameFormat unittests
Write-Output "##teamcity[importData type='nunit' path='./Reports/unittests.xml']"

The log shows that the file is passed

[Step 2/2] NUnit report watcher
[12:39:11][NUnit report watcher] 1 report found for paths:
[12:39:11][NUnit report watcher] C:\TeamCity\buildAgent\work\416967dfd65045\Reports\unittests.xml
[12:39:11][NUnit report watcher] Successfully parsed

Im using teamcity 7.1.1

Christian
  • 908
  • 1
  • 13
  • 22

1 Answers1

1

You need to ensure that Powershell exits with a non-zero exit code, say 1, so that TeamCity notices the non-zero code and stops the build due to an error.

To do this, put something like this in your script:

  $host.SetShouldExit(1);
  exit 1;

Which will cause Powershell to exit with error code 1.

You could write your script such that you catch an exception (failing tests say), and then exit as shown above. This could be done using a trap statement (powershell 1), or try/catch (powershell 2 and up).

Marcus
  • 5,987
  • 3
  • 27
  • 40
  • This does not really answer the question (have not tried it) - since it is still not reporting the number of test that parsed if there was no errors. I have given up on running the build from powershell and is just running the tests from msbuild. – Christian Nov 12 '12 at 19:10