I originally came across
this post while I was investigating why my nested builds were not failing. The suggestion to wrap calls to Invoke-Psake in "Exec" solved that problem, but I'm wondering if I've now encountered a bug in how exec checks for errors.
Specifically, it appears that if your psake script is "pure" powershell, it's possible for $lastexitcode to never be set to anything. When "exec" then checks "if ($lastexitcode -ne 0)", it fails because $lastexitcode is $null, not 0.
As a very simple example, running the command below in a fresh powershell session (and after loading the psake module) reports a failure for me:
exec { get-childitem }
Obviously you'd never bother to wrap get-childitem in an exec call, but the behavior is the same with "invoke-psake" if the script you're calling doesn't make any non-powershell calls (and no non-powershell calls have yet been made in your current session).
Should exec be checking for 0 or $null?