powershell - Psake and robocopy failing -
robocopy exit code above 0 , still possibly not failure. psake detects above 0 failure , fails build. fine, how come 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 deploy if statement hit , write-host outputs 0, correctly, yet taskteardown still detects last exit code 3! how fix this?
robocopy
exit codes below 8 non-error status codes. exit codes of 8 , above indicate error. see here.
the reason why teardown task still reports exit code of 3 because automatic variable $lastexitcode
global variable, whereas deploy task creates additional local variable $lastexitcode
masks global variable in scope of task. suggested in this answer similar question, use $global:
prefix:
$global:lastexitcode = $null
Comments
Post a Comment