Answers: <p>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. </p>
  
Answers: CC BY-SA 3.0
Answers: 2018-03-13T19:48:35.387Z
Answers: Another way to solve the problem is to copy the files in backup mode (/b flag).
Answers: Joseph Faulkner
Answers: CC BY-SA 3.0
Answers: 2018-03-13T18:28:27.570Z
Answers: 2018-03-13T18:28:27.570Z
Answers: Maria Olivero
Body: <p>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: </p>
  
  <pre><code>@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
  </code></pre>
  
  <p>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. </p>
  
  <p><a href="https://i.sstatic.net/ddxro.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ddxro.png" alt="Excecute Script To Run on Jenkins"></a></p>
  
  <p><a href="https://i.sstatic.net/0bvaY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0bvaY.png" alt="ROBOCOPY runs slowly when started from Jenkins Job"></a></p>
  
  <p>If I just run the same script directly on the (exact same) Jenkins server, the process runs a lot faster.</p>
  
  <p><a href="https://i.sstatic.net/WFWeu.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WFWeu.png" alt="Robocopy runs quickly when started directly"></a> </p>
  
  <p>What is causing the process to run slowly and how can I make the script run faster when executed from the Jenkins Job?    </p>
  
Comments: CC BY-SA 3.0
Comments: 2018-03-06T07:33:24.097Z
Comments: When you run it as a Jenkins job, does it run on the same server or on a slave node?
Comments: THelper
Comments: CC BY-SA 3.0
Comments: 2018-03-06T18:03:35.580Z
Comments: The Jenkins job is running on the master node.
Comments: Joseph Faulkner
Comments: CC BY-SA 3.0
Comments: 2018-03-06T21:01:44.650Z
Comments: Where is it copying the files to? Locally or to a remote node?
Comments: Preston Martin
Comments: CC BY-SA 3.0
Comments: 2018-03-06T21:33:56.170Z
Comments: Are you doing anything multithreaded, could it be related to cores/vcpus?
Comments: casey vega
Comments: CC BY-SA 3.0
Comments: 2018-03-06T22:36:31.033Z
Comments: The files are being copied to and from remote servers but the server's are inside the exact same internal network. Like I said, the script works just fine if you call it directly.
Comments: Joseph Faulkner
Comments: CC BY-SA 3.0
Comments: 2018-03-07T15:08:37.320Z
Comments: @JosephFaulkner Is Jenkins in the same network?
Comments: Preston Martin
Comments: CC BY-SA 3.0
Comments: 2018-03-07T18:15:26.143Z
Comments: Yes, the Jenkins server is in the same local network as the remote servers.
Comments: Joseph Faulkner
Comments: CC BY-SA 3.0
Comments: 2018-03-11T17:37:16.087Z
Comments: What Jenkins version do you use?
Comments: 030
Tags: <jenkins>
Title: Robocopy is Running Slowly on Jenkins Server
UserDisplayName: Joseph Faulkner
ThreadText: # Robocopy is Running Slowly on Jenkins Server
  
  (Asked by: username_0 on 2018-03-06)
  
  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.
  
  [![Excecute Script To Run on Jenkins](https://i.sstatic.net/ddxro.png)](https://i.sstatic.net/ddxro.png)
  
  [![ROBOCOPY runs slowly when started from Jenkins Job](https://i.sstatic.net/0bvaY.png)](https://i.sstatic.net/0bvaY.png)
  
  If I just run the same script directly on the (exact same) Jenkins server, the process runs a lot faster.
  
  [![Robocopy runs quickly when started directly](https://i.sstatic.net/WFWeu.png)](https://i.sstatic.net/WFWeu.png)
  
  What is causing the process to run slowly and how can I make the script run faster when executed from the Jenkins Job?
  
  **Tags:** jenkins
  
  > **Comments:**
  > **username_1**: When you run it as a Jenkins job, does it run on the same server or on a slave node?  
  > **username_0**: The Jenkins job is running on the master node.  
  > **username_2**: Where is it copying the files to? Locally or to a remote node?  
  > **username_3**: Are you doing anything multithreaded, could it be related to cores/vcpus?  
  > **username_0**: The files are being copied to and from remote servers but the server's are inside the exact same internal network. Like I said, the script works just fine if you call it directly.  
  > **username_2**: @username_0 Is Jenkins in the same network?  
  > **username_0**: Yes, the Jenkins server is in the same local network as the remote servers.  
  > **username_4**: What Jenkins version do you use?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_5 on 2018-03-13. Score: 2 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: Another way to solve the problem is to copy the files in backup mode (/b flag).  
  
  ---
  
  