即使按预期工作,批处理脚本也会不断给出错误代码 3

batch script keeps giving error code 3 even through it is work as intended

此脚本不断向我提供 robocopy 错误代码 3,但正在按预期工作。我创建了一个日志文件来捕获它,它在命令行和脚本中运行得很好,但我在 TFS 2015 中的构建中仍然遇到错误。有什么想法吗?

TFS 构建错误:

Exception Message: TF270015: 'RolltoDEV.bat' returned an unexpected exit code. Expected '0'; actual '3'.

这是我的脚本:

@echo off
set root="D:\Drop\PythonAutomation-DEV\PythonAutomation - CD to DEV"
CD /D %root% 
FOR /F "delims=" %%i IN ('dir /b /ad-h /t:c /od') DO SET a=%%i
CD /D C:\

robocopy "C:\Builds04\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation" "D:\Drop\PythonAutomation-DEV\PythonAutomation - CD to DEV\%a%" /E /log:D:\logFileForPython.txt

robocopy "C:\Builds04\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation" "D:\PythonAutomation" /E /log+:D:\logFileForPython.txt

这是日志文件:

------------------------------------------------------------------------------- ROBOCOPY :: Robust File Copy for Windows


开始时间:2017 年 10 月 2 日,星期一 11:04:27 AM 来源: C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\ 目的地:D:\Drop\PythonAutomation-DEV\PythonAutomation - CD 到 DEV\PythonAutomation - CD 到 DEV_20171002.23\

Files : *.*
     Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 

                 3    C:\Builds04\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\  *EXTRA Dir        -1    D:\Drop\PythonAutomation-DEV\PythonAutomation - CD to DEV\PythonAutomation - CD to DEV_20171002.23\logs\
  New File            1324    PythonAutomation.log   0%   100%  
  New File            1255    PythonAutomation.sln   0%   100%  
  New File             221    PythonAutomation.sln.Any CPU.Debug.vsprops   0%   100%        New Dir         

1 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\Python自动化\ 新文件 3552 PythonAutomation.pyproj 0% 100% 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\BaseObjects\ 新目录
1 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\配置\ 新文件 374 Config-Main.py 0% 100% New Dir 0 C:\Builds04\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\配置\属性\
新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - 光盘到 DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\ 新目录 1 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\RolltoDEV\ 新文件 520 RolltoDEV.bat 0% 100% 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\Properties\ 新目录
0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\ 新目录 4 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\BaseObjects\ 新文件 2664 Email.py 0% 100%
新文件 573 File.py 0% 100%
新文件 1260 SSHConnection.py 0% 100%
新文件 342 init.py 0% 100% 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\ 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\ 新目录 3 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\PublishProfiles\ 新文件 864 RolltoDEV.pubxml 0% 100%
新文件 934 RolltoPROD.pubxml 0% 100%
新文件 922 RolltoQA.pubxml 0% 100%


           Total    Copied   Skipped  Mismatch    FAILED    Extras
Dirs :        13        12         0         0         0         1    Files :        13        13         0         0         0         0   

字节:14.4k 14.4k 0 0 0 0
次 : 0:00:00 0:00:00 0:00:00 0:00:00
结束时间:2017 年 10 月 2 日星期一 11:04:27 上午

-------------------------------------------- ------------------------------ ROBOCOPY :: Windows [=19= 的稳健文件复制]


开始时间:2017 年 10 月 2 日,星期一 11:04:27 AM 来源: C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\ 目的地:D:\PythonAutomation\

Files : *.*
     Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 

                 3    C:\Builds04\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\  *EXTRA Dir        -1    D:\PythonAutomation\.vs\    *EXTRA Dir        -1    D:\PythonAutomation\Outputs\
  New File            1324    PythonAutomation.log   0%   100%  
  New File            1255    PythonAutomation.sln   0%   100%  
  New File             221    PythonAutomation.sln.Any CPU.Debug.vsprops   0%   100%        New Dir         

1 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\Python自动化\ 新文件 3552 PythonAutomation.pyproj 0% 100% 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\BaseObjects\ 新目录
1 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\配置\ 新文件 374 Config-Main.py 0% 100% New Dir 0 C:\Builds04\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\配置\属性\
新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - 光盘到 DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\ 新目录 1 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\RolltoDEV\ 新文件 520 RolltoDEV.bat 0% 100% 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\Properties\ 新目录
0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\ 新目录 4 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\BaseObjects\ 新文件 2664 Email.py 0% 100%
新文件 573 File.py 0% 100%
新文件 1260 SSHConnection.py 0% 100%
新文件 342 init.py 0% 100% 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\ 新目录 0 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\ 新目录 3 C:\Builds04\PythonAutomation\PythonAutomation - CD 到 DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\PublishProfiles\ 新文件 864 RolltoDEV.pubxml 0% 100%
新文件 934 RolltoPROD.pubxml 0% 100%
新文件 922 RolltoQA.pubxml 0% 100%


           Total    Copied   Skipped  Mismatch    FAILED    Extras
Dirs :        13        12         0         0         0         2    Files :        13        13         0         0         0         0   

字节:14.4k 14.4k 0 0 0 0
次 : 0:00:00 0:00:00 0:00:00 0:00:00

速度:1057500 Bytes/sec。速度:
60.510 MegaBytes/min。结束时间:2017 年 10 月 2 日星期一 11:04:27 上午

对于可能 运行 遇到此问题的任何人,由于该错误在批处理脚本中并不是真正的错误,它仍在运行,但在 TFS 中,一条错误消息是一条错误消息,因此它失败了。我为解决此问题所做的工作是通过将以下代码添加到我的 robocopy 语句的末尾来绕过我的批处理脚本中的这个特定错误。

2>&1|find /v "TF270015"

希望这对以后的人有所帮助。感谢 @RGuggisburg 向我展示了 3.

背后的真实错误信息