chrisism / VSTS.Robocopy

Robocopy task for VSTS/TFS
MIT License
3 stars 4 forks source link

Question/Concern about Robocopy error handling #17

Open mchristensen80 opened 3 years ago

mchristensen80 commented 3 years ago

Today, our Azure Pipeline displayed a green status for this task; however, only a partial copy occurred. Our logs show one successful file copied and two failed.

Here's the YAML for our task:

- task: jungeriusit.jungit-robocopy.jungit-robocopy.Robocopy@1
  displayName: 'Copy to $(TargetFolder)'
  inputs:
    source: '$(SourceFolder)'
    destination: '$(TargetFolder)'
    files: '*.*'
    copySubDirs: false
    copySubDirsAll: false
    purge: true
    move: false
    createtree: false

Here's the output from our log:

2021-04-01T13:03:43.0799425Z ##[section]Starting: Copy to C:\Program Files\Agency Insurance Company\Services\Attachment-Merge-Service
2021-04-01T13:03:43.1032539Z ==============================================================================
2021-04-01T13:03:43.1032616Z Task         : File System - Robocopy
2021-04-01T13:03:43.1032673Z Description  : Use Robocopy to perform a copy action.
2021-04-01T13:03:43.1032709Z Version      : 1.1.5
2021-04-01T13:03:43.1032760Z Author       : Jungerius IT
2021-04-01T13:03:43.1032793Z Help         : 
2021-04-01T13:03:43.1032827Z ==============================================================================
2021-04-01T13:03:43.1255936Z ##[warning]Task 'Robocopy' (1.1.5) is using deprecated task execution handler. The task should use the supported task-lib: https://aka.ms/tasklib
2021-04-01T13:03:43.1271829Z Preparing task execution handler.
2021-04-01T13:03:43.8831693Z Executing the powershell script: C:\azagent\A1\_work\_tasks\Robocopy_7db26114-8ee0-4460-b1e6-e5fbd3a9a583\1.1.5\robocopytask.ps1
2021-04-01T13:03:44.0906662Z Starting Robocopy with the following options:  /purge
2021-04-01T13:03:44.0907490Z 
2021-04-01T13:03:44.0908611Z 
2021-04-01T13:03:44.1284316Z 
2021-04-01T13:03:44.1285030Z -------------------------------------------------------------------------------
2021-04-01T13:03:44.1285243Z    ROBOCOPY     ::     Robust File Copy for Windows                              
2021-04-01T13:03:44.1285426Z -------------------------------------------------------------------------------
2021-04-01T13:03:44.1285554Z 
2021-04-01T13:03:44.1285696Z   Started : Thursday, April 1, 2021 9:03:44 AM
2021-04-01T13:03:44.1285858Z    Source : C:\azagent\A1\_work\r10\a\Staging\
2021-04-01T13:03:44.1286009Z      Dest : C:\Program Files\Agency Insurance Company\Services\Attachment-Merge-Service\
2021-04-01T13:03:44.1286133Z 
2021-04-01T13:03:44.1286286Z     Files : *.*
2021-04-01T13:03:44.1286424Z        
2021-04-01T13:03:44.1286568Z   Options : *.* /DCOPY:DA /COPY:DAT /PURGE /R:1000000 /W:30 
2021-04-01T13:03:44.1286706Z 
2021-04-01T13:03:44.1287042Z ------------------------------------------------------------------------------
2021-04-01T13:03:44.1290403Z 
2021-04-01T13:03:44.1317319Z                     302    C:\azagent\A1\_work\r10\a\Staging\
2021-04-01T13:03:44.1382153Z        Newer               1270    appsettings.json
2021-04-01T13:03:44.1388899Z 100%  
2021-04-01T13:03:44.1389691Z        Newer             170496    AttachmentMergeService.deps.json
2021-04-01T13:03:44.1389928Z  76%  
2021-04-01T13:03:44.1390162Z 100%  
2021-04-01T13:03:44.1410557Z        Newer              33792    AttachmentMergeService.dll
2021-04-01T13:03:44.1438883Z        Newer             142848    AttachmentMergeService.exe
2021-04-01T13:03:44.1454614Z        Newer              25124    AttachmentMergeService.pdb
2021-04-01T13:03:44.1461543Z 100%  
2021-04-01T13:03:44.1479387Z        Newer                178    AttachmentMergeService.runtimeconfig.json
2021-04-01T13:03:44.1484218Z 100%  
2021-04-01T13:03:44.1484379Z 
2021-04-01T13:03:44.1485379Z ------------------------------------------------------------------------------
2021-04-01T13:03:44.1485505Z 
2021-04-01T13:03:44.1487121Z                Total    Copied   Skipped  Mismatch    FAILED    Extras
2021-04-01T13:03:44.1487250Z     Dirs :         1         0         1         0         0         0
2021-04-01T13:03:44.1488803Z    Files :       302         4       296         0         2         0
2021-04-01T13:03:44.1489070Z    Bytes :  101.05 m   192.4 k  100.70 m         0   172.5 k         0
2021-04-01T13:03:44.1489897Z    Times :   0:00:00   0:00:00                       0:00:00   0:00:00
2021-04-01T13:03:44.1490125Z 
2021-04-01T13:03:44.1490845Z 
2021-04-01T13:03:44.1491885Z    Speed :            12316750 Bytes/sec.
2021-04-01T13:03:44.1492880Z    Speed :             704.770 MegaBytes/min.
2021-04-01T13:03:44.1493996Z    Ended : Thursday, April 1, 2021 9:03:44 AM
2021-04-01T13:03:44.1494324Z 
2021-04-01T13:03:44.1755839Z ##[section]Finishing: Copy to C:\Program Files\Agency Insurance Company\Services\Attachment-Merge-Service

I suspect that this is due to how the PowerShell script is handling errors. According to Microsoft's documentation on Robocopy (https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy), a return code of eight indicates a problem. In version 1.1.5 of the task, the script only returns an error when the robocopy return code is greater than eight. Shouldn't the script return an error if the code is greater than or equal to eight?

Here's the current code for robocopytask.ps1 lines 71-76

if($LastExitCode -gt 8) {
    exit 1
}
else {
    exit 0
}
Oliverax commented 3 years ago

As someone who wrote a wrapper script for robocopy myself, to deal with exactly these return codes, I agree this is wrong. Maybe a classic powershell typo. Shoud be "-ge", not "-gt".