Build and Deploy files in multiple folders in SVN into multiple folder in destination server

822 views Asked by At

I am looking to automate a manual copy paste activity using SVN, Jenkins and Urban Code Deploy.

We have now created a SVN repo to have the same directory structure of the Unix server Dir structure. The challenge is, I cannot do a clean deploy as I only have to pick file which is changed in any of the folder and place it in the respective folder on the Unix server.

I am not able to figure out how to create a Jenkins job to pick files from multiple folders and create one package and deploy using Urban Code Deploy to multiple folders on the destination server.

a   
|------b
|   --------b
c
|-------d
    --------v
        --------m

This is just an illustration of the folder structure, in SVN and Unix server. Any help is appreciated

2

There are 2 answers

2
ANIL On

You can pick only the modified files for a particular revision using the following commands and check them out to their respective directories in your Unix server:

svn checkout https://org.svn.host/path/to/your/file /path/to/target_dir --depth empty --revision <revisionNumber>

cd /path/to/target_dir

svn up file_you_want

0
Parth H. Jadav On

I have made one PowerShell Script to pick up files from multiple folders. I also do the same thing for some Jenkins projects. So I hope it will help you. Please free feel to ask any help to understand the below script and/or how to use this script.

Script :-

#################  USER INPUT STARTS #####################################################################################################
$TARGET=""                                    #Give target path where you want to get only changed files with folder structure#
$SRCFILE=""                                   #Source path, your SVN checkout#
$SVNURL=""                                    #Give Repository URL For eg. "svn://0.0.0.0/abc/trunk/def"
$FINDSTR=""                                   #Give Value For eg. "trunk/def/" 
$Daysback="-06"                               #Give number of days. For eg. give "-01" if you want to get changed files from last 1 Day#
#################  USER INPUT ENDS #####################################################################################################
$CurrentDate=Get-Date
$DatetoDelete=$CurrentDate.AddDays($Daysback)
$Daysback="1"
$CurrentDate=Get-Date
$CurrentDate=$CurrentDate.AddDays($Daysback)
$FROM1=$CurrentDate.Year
$FROM2=$CurrentDate.Month
$FROM3=$CurrentDate.Day
$TO1=$DatetoDelete.Year
$TO2=$DatetoDelete.Month
$TO3=$DatetoDelete.Day
[string]$FROM = (get-date).ToString("$FROM1-$FROM2-$FROM3");
[string]$TO = (get-date).ToString("$TO1-$TO2-$TO3");
[string]$DATE = "{$FROM}:{$TO}";
$DATE                           
$DIFFER=D:\Subversion\bin\svn diff "$SVNURL" --summarize -r $DATE      #Here you have to give absolute path of your "svn.exe"  

IF($DIFFER)
{
    IF($DIFFER.count -GT 1)
    {
        for($i=0; $i -le ($DIFFER.Count-1); $i++)
        {
            $SYS11=$DIFFER[$i]
            $APP11=($SYS11 -SPLIT ',*'+$FINDSTR)[1]
            $FILEDIR="$APP11"
            $FILE=Split-Path $APP11 -leaf 
            $EXTENSION=(Split-Path -Path $FILE -Leaf).Split(".")[1];
            IF($EXTENSION)
            {
                $FILEDIR =$FILEDIR -replace $FILE, ""
                $TARGETDIR="$TARGET\$FILEDIR"
                IF (!(Test-Path $TARGETDIR))
                {
                    New-Item $TARGETDIR -type Directory > $null 
                }
                $FROM="$SRCFILE\$APP11"
                $TARGETFILE="$TARGET\$APP11"
                IF(Test-Path $FROM)
                {
                    Copy-Item $FROM $TARGETFILE -force
                    ECHO "==============================================================================="
                    ECHO "$FROM"
                    ECHO "**************"
                    ECHO "$TARGETFILE"
                    ECHO "**************"
                    ECHO "NAME OF COPIED FILE  ::: $FILE"
                }
                ELSE
                {
                    ECHO "NOT FOUND $FROM"
                }
            }   
        }    
    }
    ELSE
    {
        $SYS11=$DIFFER
        $APP11=($SYS11 -SPLIT ',*'+$FINDSTR)[1]
        $FILEDIR="$APP11"
        $FILE=Split-Path $APP11 -leaf 
        $EXTENSION=(Split-Path -Path $FILE -Leaf).Split(".")[1];
        IF($EXTENSION)
        {
            $FILEDIR =$FILEDIR -replace $FILE, ""
            $TARGETDIR="$TARGET\$FILEDIR"
            IF (!(Test-Path $TARGETDIR))
            {
                New-Item $TARGETDIR -type Directory > $null 
            }
            $FROM="$SRCFILE\$APP11"
            $TARGETFILE="$TARGET\$APP11"

            IF(Test-Path $FROM)
            {
                Copy-Item $FROM $TARGETFILE -force
                ECHO "==============================================================================="
                ECHO "$FROM"
                ECHO "**************"
                ECHO "$TARGETFILE"
                ECHO "**************"
                ECHO "NAME OF COPIED FILE  ::: $FILE"
            }
            ELSE
            {
                ECHO "NOT FOUND $FROM"
            }
        }
    }
}
ELSE
{
    ECHO "NO CHANGE IN $SVNURL"
}