Robocopy will exit with a code above 0 and still possibly not be a failure. PSake detects anything above 0 as a failure and fails the build. This is fine, but how come this still fails:
task Deploy {
robocopy $source $dest /NP /S /XO /NFL /NDL /NJH /NJS | Out-Default
if ($lastexitcode -eq 3)
{
Write-Host "Got Here"
$lastexitcode = 0
}
Write-Host "Deploy local complete"
Write-Host $lastexitcode
}
TaskTearDown {
if ($LastExitCode -ne 0) {
write-host "Build failed"
exit 1
}
}
I can verify that the Deploy if statement is hit and the Write-Host outputs 0, correctly, yet the TaskTearDown still detects the last exit code as 3! How do I fix this?
robocopy
exit codes below 8 are non-error status codes. Only exit codes of 8 and above indicate an error. See here.
The reason why your teardown task still reports an exit code of 3 is probably because the automatic variable $LastExitCode
is a global variable, whereas your deploy task creates an additional local variable $lastexitcode
that masks the global variable in the scope of the task. As suggested in this answer to a similar question, use the $global:
prefix:
$global:LastExitCode = $null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With