We're using the following statement to enable TeamCity to recognize errors in our PowerShell deployment scripts:
trap { $host.SetShouldExit(1) }
This works fine, however, since Param(...) needs to be the very first statement we have to use this order:
Param(
...
)
Set-StrictMode -Version 2.0
$ErrorActionPreference = "Stop"
trap { $host.SetShouldExit(1) }
Is there any way to also trap errors during the Param() evaluation? E.g. if we omit a mandatory parameter, TeamCity is not able to detect this at the moment.