Robocopy is Running Slowly on Jenkins Server I'm working to automate the deployment process for a Fullstack application using Jenkins. The app is deployed on a Windows Server. The .cmd script I have to automatically deploy the app is this: 

@ECHO OFF
REM SET THE PARAMETERS FOR THE SCRIPT TO RUN
SET CONFIG_ENV=%1
SET SERVER_DOMAIN=%2
SET ADMIN_LOGIN=%3
SET ADMIN_PASS=%4
SET ARTIFACT_DIR=%~5
SET DROPFOLDER_PATH=%~6
SET DEPLOY_PATH=%~7
SET SERVICE_NAME=%8

REM ECHO THE PARAMETERS OUT TO THE CONSOLE (SO WE CAN SEE WHAT'S GOING ON)
ECHO ...
ECHO RUNNING WCF AUTO DEPLOYMENT. PARAMETERS ARE: 
ECHO CONFIG_ENV      : %CONFIG_ENV%
ECHO SERVER_DOMAIN   : %SERVER_DOMAIN%
ECHO ADMIN_LOGIN     : %ADMIN_LOGIN%
ECHO ADMIN_PASS      : %ADMIN_PASS%
ECHO ARTIFACT_DIR    : %ARTIFACT_DIR%
ECHO DROPFOLDER_PATH : %DROPFOLDER_PATH%
ECHO DEPLOY_PATH     : %DEPLOY_PATH%
ECHO SERVICE_NAME    : %SERVICE_NAME%
ECHO ...

REM SELECT THE LATEST SET OF RELEASE ARTIFACTS FROM THE DSL 
FOR /F "delims=" %%i IN ('dir "%ARTIFACT_DIR%" /b /ad-h /t:c /od') DO SET latest_build=%%i
ECHO DEPLOYING ARTIFACTS IN: %ARTIFACT_DIR%\%latest_build% (latest build)
ECHO DEPLOYING TO "\\%SERVER_DOMAIN%\%DROPFOLDER_PATH%"
ECHO ...
REM LOGIN TO DEPLOY TO THE SERVER 
net use \\%SERVER_DOMAIN% %ADMIN_PASS% /USER:%ADMIN_LOGIN% 

REM COPY ALL THE RELEASE ARTIFACTS TO THE DROP LOCATION ON THE SERVER
ECHO COPYING ARTIFACTS TO DROP FOLDER
ROBOCOPY "%ARTIFACT_DIR%\%latest_build%" "\\%SERVER_DOMAIN%\%DROPFOLDER_PATH%" /MIR /is /it /np /r:1 /w:1 /eta /tee /copy:DT
ECHO ...

REM STOP THE SERVICE SO THAT WE CAN UPDATE THE FILES 
ECHO STOPPING THE SERVICE
SC \\%SERVER_DOMAIN% STOP %SERVICE_NAME%
ECHO ...

REM COPY ALL THE .DLLs and .EXEs FILES
ECHO COPYING .DLL AND .EXE FILES
ROBOCOPY "\\%SERVER_DOMAIN%\%DROPFOLDER_PATH%" "\\%SERVER_DOMAIN%\%DEPLOY_PATH%" *.dll *.exe /is /it /np /r:1 /w:1 /eta /tee /copy:DT
ECHO ...

REM COPY THE APPROPRIATE CONFIGURATION FILE FOR THE ENVIRONMENT
ECHO COPYING CONFIGURATION FILE
ROBOCOPY "\\%SERVER_DOMAIN%\%DROPFOLDER_PATH%\Configuration_Files\%CONFIG_ENV%" "\\%SERVER_DOMAIN%\%DEPLOY_PATH%" *.config /is /it /np /r:1 /w:1 /eta /tee /copy:DT
ECHO ...

REM START THE SERVICE BACK UP AGAIN
ECHO STARTING THE SERVICE
SC \\%SERVER_DOMAIN% START %SERVICE_NAME%
ECHO ...

REM AND WE ARE DONE
ECHO SCRIPT COMPLETE


If I run the script directly from where it's located on the Jenkins Server, the script finishes in a matter of seconds. However, when I queue the script to run from a Jenkins job, the ROBOCOPY command takes roughly a minute to copy each file. 





If I just run the same script directly on the (exact same) Jenkins server, the process runs a lot faster.

 

What is causing the process to run slowly and how can I make the script run faster when executed from the Jenkins Job?
This issue is resolved.  Robocopy has a lot of smart features and functions that allow it to check and see if the files being copied are actually different.  Unfortunately that comparison is where the time is really going.  Once we changed the script to delete the files from the destination folder first (every time) - we should have a repeatable process that runs in ~10-15 seconds.