Search code examples
batch-filetfstfs-2015windows-server-2012

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


This script keeps giving me error code 3 for the robocopy but is working as intended. I created a log file to capture it and it runs just fine in command line and in script but I still get an error on My Build in TFS 2015. Any ideas?

TFS build error :

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

here is my script:

@echo off
set root="D:\Drop\PythonAutomation\1-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:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation" "D:\Drop\PythonAutomation\1-DEV\PythonAutomation - CD to DEV\%a%" /E /log:D:\logFileForPython.txt

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

Here is the log file:

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


Started : Monday, October 2, 2017 11:04:27 AM Source : C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\ Dest : D:\Drop\PythonAutomation\1-DEV\PythonAutomation - CD to DEV\PythonAutomation - CD to DEV_20171002.23\

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

                 3    C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\  *EXTRA Dir        -1    D:\Drop\PythonAutomation\1-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:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\ New File 3552 PythonAutomation.pyproj 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\BaseObjects\ New Dir
1 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\ New File 374 Config-Main.py 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\
New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\ New Dir 1 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\RolltoDEV\ New File 520 RolltoDEV.bat 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Properties\ New Dir
0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\ New Dir 4 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\BaseObjects\ New File 2664 Email.py 0% 100%
New File 573 File.py 0% 100%
New File 1260 SSHConnection.py 0% 100%
New File 342 init.py 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\ New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\ New Dir 3 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\PublishProfiles\ New File 864 RolltoDEV.pubxml 0% 100%
New File 934 RolltoPROD.pubxml 0% 100%
New File 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   

Bytes : 14.4 k 14.4 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Monday, October 2, 2017 11:04:27 AM

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


Started : Monday, October 2, 2017 11:04:27 AM Source : C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\ Dest : D:\PythonAutomation\

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

                 3    C:\Builds\1004\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:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\ New File 3552 PythonAutomation.pyproj 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\BaseObjects\ New Dir
1 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\ New File 374 Config-Main.py 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\
New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\ New Dir 1 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Configuration\Properties\PublishProfiles\RolltoDEV\ New File 520 RolltoDEV.bat 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\Properties\ New Dir
0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\ New Dir 4 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\BaseObjects\ New File 2664 Email.py 0% 100%
New File 573 File.py 0% 100%
New File 1260 SSHConnection.py 0% 100%
New File 342 init.py 0% 100% New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\ New Dir 0 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\ New Dir 3 C:\Builds\1004\PythonAutomation\PythonAutomation - CD to DEV\src\PythonAutomation\PythonAutomation\PythonAutomation\Properties\PublishProfiles\PublishProfiles\ New File 864 RolltoDEV.pubxml 0% 100%
New File 934 RolltoPROD.pubxml 0% 100%
New File 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   

Bytes : 14.4 k 14.4 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00

Speed : 1057500 Bytes/sec. Speed :
60.510 MegaBytes/min. Ended : Monday, October 2, 2017 11:04:27 AM


Solution

  • For anyone who may run into this issue, since the error wasn't really an error in the batch script it was still working but in TFS an error message is an error message so it failed. What I did to fix this issue is to bypass this specific error in my batch script by adding the following code to the end of my robocopy statements.

    2>&1|find /v "TF270015"
    

    Hope this helps someone in the future. Thanks to @RGuggisburg for showing me the real error message behind 3.