I'm using robocopy to copy files during a build step in a Gitlab pipeline. The pipeline tasks are executed in powershell.
The exit status of robocopy results in a failure of my build step. I noticed all statuscodes under 8 are valid. Meaning I should reset the $lastexitcode to $null if the $lastexitcode is < 8
This is what I tried in my powershell script:
robocopy src dest /mir (&{if ($lastexitcode -lt 8) { $global:LASTEXITCODE = $null }})
The problem here is that the (&{ if... part is executed before robocopy.
You must use two statements, separated by ;:
robocopy src dest /mir; if ($lastexitcode -lt 8) { $global:LASTEXITCODE = $null }
In your attempt the (in this case empty) output of the (...) expression was passed as an argument to robocopy and, as you've observed, expressions passed as arguments are (of necessity) evaluated first.
Note: Robocopy's exit codes 0 through 7 are non-error exit codes, hence the -le 8 condition - see https://ss64.com/nt/robocopy-exit.html
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