3

In a small PowerShell build script I build and test a .NET application.

I now want to prevent further steps in the script if the tests result in one or more failures.

I tried to get the result of the test like this:

$exitcode = dotnet test  .\Domain.Tests
Write-Host "result $exitcode" 

but unfortunately it doesn't return an exit code indicating success I just get the test testing description.

Is there a better way then parsing the string output for the failed tests count?

Boas Enkler
  • 12,264
  • 16
  • 69
  • 143

1 Answers1

11

There is a $lastexitcode automatic variable, you can check that for the exit code.

Mark Wragg
  • 22,105
  • 7
  • 39
  • 68
4c74356b41
  • 69,186
  • 6
  • 100
  • 141