I set a Command Line phase in a TFS Builds to execute a Robocopy and it returns an error code 1, although there are no errors during the robocopy execution.
If I run the Robocopy command directly in the Cmd it works, and the Job log shows that the Robocopy works porperly until the end:
2019-02-27T10:21:58.3234459Z                Total    Copied   Skipped  
Mismatch    FAILED    Extras
2019-02-27T10:21:58.3234459Z     Dirs :      1688         0      1688         0         0         0
2019-02-27T10:21:58.3234459Z    Files :      6107         6      6101         0         0         0
2019-02-27T10:21:58.3234459Z    Bytes :  246.01 m   299.2 k  245.71 m         0         0         0
2019-02-27T10:21:58.3234459Z    Times :   0:00:17   0:00:00                       0:00:00   0:00:17
2019-02-27T10:21:58.3234459Z 
2019-02-27T10:21:58.3234459Z 
2019-02-27T10:21:58.3234459Z    Speed :             3879329 Bytes/sec.
2019-02-27T10:21:58.3234459Z    Speed :             221.976 MegaBytes/min.
2019-02-27T10:21:58.3234459Z 
2019-02-27T10:21:58.3234459Z    Ended : Wed Feb 27 11:21:58 2019
2019-02-27T10:21:58.3702460Z ##[error]Process completed with exit code 1.
Here is an image about the Build configuration:

RoboCopy has ExitCodes > 0.
In your example Exit Code = 1 means One or more files were copied successfully (that is, new files have arrived).
To fix this you could create a Powershell Script, which executes the copy and overwrites the Exit code.
like
param( [String] $sourcesDirectory, [String] $destinationDirectory, [String] $attributes)
robocopy $sourcesDirectory $destinationDirectory $attributes
if( $LASTEXITCODE -ge 8 )
{
    throw ("An error occured while copying. [RoboCopyCode: $($LASTEXITCODE)]")
}
else
{
    $global:LASTEXITCODE = 0;
}
exit 0
robocopy use the error code different, error code 1 is not a real error, it just saying that one or more files were copied successfully.
TFS recognize error code 1 as a real error and fail the build.
To solve that you need to change the robocopy error code:
(robocopy c:\dirA c:\dirB *.*) ^& IF %ERRORLEVEL% LEQ 1 exit 0
The ^& IF %ERRORLEVEL% LEQ 1 exit 0 convert the error code 1 to 0 and then the TFS build will not be failed.
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