Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Psake and robocopy failing

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?

like image 642
chum of chance Avatar asked May 14 '13 01:05

chum of chance


1 Answers

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
like image 105
Ansgar Wiechers Avatar answered Oct 05 '22 22:10

Ansgar Wiechers