I use CAKE 0.22.0 and TeamCity 9.x.
In TeamCity, I have only one build step invoking build.ps1
. In turn, it runs build.cake
.
In build.ps1
, I have added the following:
trap
{
write-output $_
##teamcity[buildStatus status='FAILURE' ]
exit 1
}
The reason is to circumvent a known PowerShell bug (i.e., executing a script with -file
returns an exit code of 0 when it shouldn't).
When the exception is thrown within build.ps1
, TeamCity correctly displays the build failure:
However, if an error occurs within build.cake
, TeamCity incorrectly claims that everything ran successfully:
Here is the corresponding build log for the "successful" build referenced by the screenshot above:
As you can see, the error was thrown within a build.cake
task. This error was not captured by the trap
clause in build.ps1
, and so TeamCity was not informed of the build failure.
I thought about adding an OnError
clause to all my tasks in build.cake
(the clause will contain something similar to Information(@"Some error message\n##teamcity[buildStatus status='FAILURE']]"
)), but this will lead to a ghastly amount of duplicate code.
Is there a succinct way to ensure that any errors thrown within the tasks in build.cake
are caught in the trap
clause in build.ps1
?