<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>

CC BY-SA 3.0
2018-03-13T19:48:35.387Z
Another way to solve the problem is to copy the files in backup mode (/b flag).
Joseph Faulkner
CC BY-SA 3.0
2018-03-13T18:28:27.570Z
2018-03-13T18:28:27.570Z
Maria Olivero
<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>

CC BY-SA 3.0
2018-03-06T07:33:24.097Z
When you run it as a Jenkins job, does it run on the same server or on a slave node?
THelper
CC BY-SA 3.0
2018-03-06T18:03:35.580Z
The Jenkins job is running on the master node.
Joseph Faulkner
CC BY-SA 3.0
2018-03-06T21:01:44.650Z
Where is it copying the files to? Locally or to a remote node?
Preston Martin
CC BY-SA 3.0
2018-03-06T21:33:56.170Z
Are you doing anything multithreaded, could it be related to cores/vcpus?
casey vega
CC BY-SA 3.0
2018-03-06T22:36:31.033Z
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.
Joseph Faulkner
CC BY-SA 3.0
2018-03-07T15:08:37.320Z
@JosephFaulkner Is Jenkins in the same network?
Preston Martin
CC BY-SA 3.0
2018-03-07T18:15:26.143Z
Yes, the Jenkins server is in the same local network as the remote servers.
Joseph Faulkner
CC BY-SA 3.0
2018-03-11T17:37:16.087Z
What Jenkins version do you use?
030
<jenkins>
Robocopy is Running Slowly on Jenkins Server
Joseph Faulkner
# 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. 


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?

**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**: @JosephFaulkner 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).  

---

