4

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

ROBOCOPY runs slowly when started from Jenkins Job

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

What is causing the process to run slowly and how can I make the script run faster when executed from the Jenkins Job?

  • 1
    When you run it as a Jenkins job, does it run on the same server or on a slave node? – THelper Mar 6 '18 at 7:33
  • The Jenkins job is running on the master node. – Joseph Faulkner Mar 6 '18 at 18:03
  • Where is it copying the files to? Locally or to a remote node? – PrestonM Mar 6 '18 at 21:01
  • Are you doing anything multithreaded, could it be related to cores/vcpus? – casey vega Mar 6 '18 at 21:33
  • 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 Mar 6 '18 at 22:36
2

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.

  • Another way to solve the problem is to copy the files in backup mode (/b flag). – Joseph Faulkner Mar 13 '18 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.