Skip to content

PowerShell – SVN checkout/Update with the directory structure

Last updated on November 22, 2022

In this post, we gonna write a PowerShell script to SVN checkout or update the destination folder with the PowerShell script.

We gonna create a function called SVNCheckoutOrUpdate function and it is going to have two parameters, one is the array of svn URLs and the second one is the destination path.

function SVNCheckoutOrUpdate
{
    param
    (
        [Array] $svnUrls,
        [string] $outputPath = $Env:WORKSPACE
    )
    foreach ($svnUrl in $svnUrls) {

        $svnUri = [System.Uri]$svnUrl;
        $domain = "$($svnUri.Scheme)://$($svnUri.Authority)"

        $svnRootDir = $svnUrl -Replace $domain;

        $checkoutPath = Join-Path -Path "$outputPath" -ChildPath "$svnRootDir";

        write-host "svn checkout `"$svnUrl`" `"$checkoutPath`"";

        if (!(Test-Path -Path "$checkoutPath")) {
            svn checkout "`"$svnUrl`"" "`"$checkoutPath`""
        } else {
            svn update "`"$checkoutPath`""
        }
        
    }
}

Testing / Usage

# array of svn end point to checkout
$svnPaths = @("svn://svn.arjunphp.com/Config", 
                "svn://svn.arjunphp.com/internal/Server Config/WebServer/Compose")

# call function
SVNCheckoutOrUpdate
 $svnPaths "C:\Jenkins\workspace\Docker-Compose-Build\svn"

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments