Execute SVN Update in Jenkins - Copy a Folder to Web root Explicitly from SVN as a Build Step

5.1k views Asked by At

I'm new to Jenkins CI.I'm trying to get SVN update (myFolder) inside a job as build steps. I want to explicitly copy some files to web root as I can't have them inside my solution.

Build Steps I need to perform.

  1. Build Solution
  2. Publish
  3. Copy myFolder to web root
  4. Sync

Up to Publish it works fine.Problem when trying to copy/update myFolder to web root. MyFolder is located out of the project solution folder as I cant have it inside solution Folder.

Note: This myFolder has serialized items/object that I need to Sync in the next step.It should be copied to web root in-order to sync. And this folder is committed to SVN.

In my local CMD following batch file works fine but when I try in Jenkins Execute Windows Batch Command it stops at

-- Updating source from SVN -- Running update...

@echo off

cls
echo     -- Initiating system instance variables...
echo.    -- Setting the variables...

:: Here you need to make some changes to suit your system.
set SOURCE=C:\inetpub\wwwroot\Test\Website\App_Data\myFolder\
set SVN=C:\Program Files\TortoiseSVN\bin

:: Unless you want to modify the script, this is enough.

echo. %SOURCE%
echo. %SVN%
echo. ++ Done setting variables.
echo.
echo    -- Updating source from SVN
echo.   -- Running update...
"%SVN%\TortoiseProc.exe" /command:update /path:"%SOURCE%" /closeonend:1
echo. ++ Done.

echo. -- Cleaning up...
set SOURCE=
set SVN=
echo. ++ Done.

I have Subversion Plugin installed.Any solution for this problem.

And Also I tried using below Powershell Script

#Get checkout folder
TortoiseProc.exe /command:"update" /path:"C:\inetpub\wwwroot\Test\Website\App_Data\myFolder\"

It works in my local Windows Powershell but not in Jenkins Windows Powershell

1

There are 1 answers

1
Anthony Forloney On BEST ANSWER

In an effort to help answer your question, I will explain the configuration of a job which should accommodate what you are trying to achieve: building a project under version control after an svn update has been performed and moving the generated files to a separate directory.


Setup the Source Code Management section

Within this section in your job's configuration page, choose the appropriate version control system (ie, Subversion) and point the job to your project's URL, noted below. Also be mindful to select the appropriate check-out strategy. This is what Jenkins will use when your job runs (ie, svn update) as Jenkins will store a copy of your repository on the build-server in the job's workspace.

enter image description here

Without proceeding any further, this job will only pull down any changes from your repository through the appropriate check-out strategy configured above when this job runs.

However, you would like Jenkins job to actually do something meaningful when the job runs, such as build/publish your project. This is achieved through build steps, so let's configure build steps.

Configure the appropriate build step(s)

Build/Publish Website Locally

Assuming you have scripts already written to build/publish the website under version control (let's call it !Publish Website.bat as an example) which builds the project and publishes it locally, you can configure the step underneath the Build section as follows,

enter image description here

Note: %WORKSPACE% is a built-in environment variable which resolves to the current workspace of the job. There is a link under the build-step to list all the different environment variables exposed which can be used.

Without proceeding any further, the job will now pull down any changes and execute the batch file to publish/build a website locally within your workspace when this job runs.

Not quite done considering you wish to have these newly generated files to reside within your website's webroot folder so these changes are reflected on your website. For simplicity's sake we can go ahead and add another build-step to perform the copy.

Copy Contents to Webroot

Assuming you have scripts already written to copy the contents of the website under version control (let's call it !Copy Website.bat) which takes the published files and copies them to the appropriate directory on your webserver, you can configure the step underneath the Build section as follows,

enter image description here

Now when the job runs, it will perform an svn update against the repository on it's local workspace and execute the preceeding build-steps (ie, build/publish the solution and copy the contents to your webroot.)