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.
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