Psake and robocopy error

Robocopy will exit with code above 0 and may not fail. PSake detects anything above 0 as a failure and does not complete the build. This is normal, but why it 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 hit and Write-Host returns 0, correctly, but TaskTearDown still detects the last exit code as 3! How to fix it?

+7
source share
1 answer

robocopy codes below 8 are error-free status codes. Only exit codes 8 and above indicate an error. See here .

The reason your teardown task is still reporting exit code from 3 is probably because the $LastExitCode automatic variable is a global variable, while your deployment task creates an additional $LastExitCode local variable that masks the global variable in the task area. As suggested in this answer on a similar question, use the $global: prefix:

 $global:LastExitCode = $null 
+9
source

All Articles