Windows "robocopy exit code 1 treated as failure" in CI
robocopy uses a bitmask exit code where values 1-7 indicate success with details (files copied, extras, mismatches). CI treats any non-zero exit as failure, so a successful copy fails the step.
What this error means
A robocopy step that clearly copied files fails the job with exit code 1. Deterministic: robocopy returns 1 whenever it copied at least one file.
Total Copied Skipped Mismatch FAILED Extras
Files: 5 5 0 0 0 0
robocopy exited with code 1
##[error]Process completed with exit code 1.Common causes
robocopy non-zero codes are not errors
robocopy returns a bitmask: 0 = nothing to do, 1 = files copied, up to 7 still indicate success with extras/mismatches. Only 8 and above are real failures.
The shell maps any non-zero to failure
PowerShell and Actions treat exit codes 1-7 as failure by default, contradicting robocopy convention.
How to fix it
Normalize the exit code after robocopy
Treat anything below 8 as success and only fail on 8+.
robocopy src dst /E
if ($LASTEXITCODE -ge 8) { exit $LASTEXITCODE } else { exit 0 }Use a cmd one-liner to mask success codes
Clamp the exit code in a cmd step.
robocopy src dst /E
if %ERRORLEVEL% LSS 8 exit /b 0How to prevent it
- Always post-process robocopy exit codes, failing only on 8 or higher, so successful copies do not fail the step.