4

We have a large SVN repository and I would like to do a sparse checkout on Jenkins. I do understand the concept of sparse checkouts and having it locally I can get things to work as I would like to have it. Doing things on Jenkins however and running it repeatedly I can't get to work.

I have a repo structure as follows

trunk\file.txt
trunk\FolderA
trunk\FolderB
trunk\FolderC
trunk\FolderD

I would like to checkout and update

trunk\file.txt
trunk\FolderA
trunk\FolderB

but NOT

trunk\FolderC
trunk\FolderD

My pipeline code is as follows

checkout([$class: 'SubversionSCM', 
    additionalCredentials: [[credentialsId: strCredentialsId, realm: strRealm]],
    excludedCommitMessages: '', 
    excludedRegions: '', 
    excludedRevprop: '', 
    excludedUsers: '', filterChangelog: false, 
    ignoreDirPropChanges: false, 
    includedRegions: '', 
    locations: [
        [
            remote: "${strRepoPath}/trunk",
            local: "${softwarePath}", 
            depthOption: 'unknown', 
            credentialsId: strCredentialsId,
            cancelProcessOnExternalsFail: true, 
            ignoreExternalsOption: false
        ],
        [
            remote: "${strRepoPath}/trunk/FolderA",
            local: "${softwarePath}/FolderA", 
            depthOption: 'infinity', 
            credentialsId: strCredentialsId, 
            cancelProcessOnExternalsFail: true, 
            ignoreExternalsOption: false
        ],
        [
            remote: "${strRepoPath}/trunk/FolderB",
            local: "${softwarePath}/FolderB", 
            depthOption: 'infinity', 
            credentialsId: strCredentialsId, 
            cancelProcessOnExternalsFail: true, 
            ignoreExternalsOption: false
        ]
    ],
    quietOperation: false, 
    workspaceUpdater: [$class: 'UpdateWithCleanUpdater']])

Whenever I run this code the first time, everything looks as expected. However, when Jenkins runs it the following times, the UpdateWithCleanUpdater causes that FolderA and FolderB get first deleted and then checked out again. The result is still correct, however, it takes much longer that I would like it to take and longer than necessary.

I would like to keep the UpdateWithCleanUpdater because I want Jenkins to clean up files generated in the previous run.

Is there any solution to this using the Jenkins SVN plugin? How would I do this "manually", i.e. do a checkout the first time, clean up and only update the following times, and still do automatic Jenkins runs based on change detection on the SVN repo?

Thanks in advance!

nogenius
  • 574
  • 1
  • 6
  • 18

2 Answers2

2

Now that is a very narrow issue. I'd say, either you replace the UpdateWithCleanUpdater with a manual script (by calling your local svn client; some examples here); or you could fork or contribute to the Jenkins SVN plugin.

Saucistophe
  • 314
  • 2
  • 10
  • This might work, however seems to be very inconvenient, because every file/folder needs to be handled separately. FolderA and FolderB are considered as unversioned when looking at the root directory trunk/. _svn info_ is showing _?_ for these folders – nogenius May 06 '19 at 10:01
  • 1
    With the _svn info is showing ?_ you might be in the situation that I called "normal checkout into another SVN workspace", in my answer. The commands to do the "sparse checkout" look like: `svn checkout --depth empty https://yourRepo workspace ; svn update --set-depth empty workspace/trunk ; svn update workspace/trunk/FolderA workspace/trunk/file.txt workspace/trunk/FolderB` – David L. Mar 08 '21 at 10:08
1

On the trunk you have:

depthOption: 'unknown',

Shouldn't the value be 'empty'?

Yet, while what that might avoid the "FolderA and FolderB get first deleted and then checked out again", so I doubt that you would really get the "sparse checkout" in this way. It will be rather a "normal checkout into another SVN workspace".

As a workaround you can consider using svn:externals: Create a folder trunk/JenkinsWorkspace/trunk, and set svn:externals property with a content like:

 ^/trunk/FolderA FolderA
 ^/trunk/FolderB FolderB
 ^/trunk/file.txt file.txt

Then, in Jenkins you would just have a single checkout from ${strRepoPath}/JenkinsWorkspace.

David L.
  • 3,149
  • 2
  • 26
  • 28