Robocopy in TFS Build PowerShell Step Reports Failure But Has No Error Robocopy in TFS Build PowerShell Step Reports Failure But Has No Error powershell powershell

Robocopy in TFS Build PowerShell Step Reports Failure But Has No Error


TL;DR Check the exit codes used in the calls, or use exit to leave the script.


RoboCopy uses a suite of exit codes including:

0×00 0 No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.

0×01 1 One or more files were copied successfully (that is, new files have arrived).

(Full List Here)

Because the script didn't have an exit statement the value of $LastExitCode was 1 which makes sense for Robocopy but causes TFS to believe the script to fail.

Using exit supressed the Robocopy exit code so TFS believed the script to have worked. However, this meant that any Robocopy information was being suppressed.

Changing the final line to exit ($LastExitCode -band 24) solved the issue properly, as per this article.