Search code examples
jenkinssvngroovyversionworkspace

How to set subversion workspace format with a Groovy script in Jenkins?


I'm trying to change the Subversion workspace format of the SubversionSCM plugin programmatically (Img). Naturally, I've been trying with a groovy script, but I cannot find any method of doing so.

I was able to retrieve the current format by running this script in a Groovy console:

import jenkins.model.*

def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("hudson.plugins.git.GitSCM")
desc =inst.getDescriptor("hudson.scm.SubversionSCM")

println(desc.getWorkspaceFormat())

This prints out 31 which is correct. It is the value of the "WC_FORMAT_18" member found in the interface "ISVNWCDb" interface of "svnkit". You can see it being used in the git repository of the plugin here.

Searching the documentation of subversion plugin I could not find any method of setting it, nor any public method in the SubversionSCM descriptor.

Is there any way of configuring that setting programmatically. I would prefer a groovy script, but at the moment anything would do.


Solution

  • I was struggling with the same thing and found something that seems to work. As you already found out, there's no setter for the workspace format on the SubversionSCM descriptor, but the workspace format is in there as a private field.

    This seems to do the trick for me:

    def required_format = 31 //31 is SVN 1.8 WF.
    svn_desc = instance.getDescriptor("hudson.scm.SubversionSCM")
    if(svn_desc.getWorkspaceFormat() != required_format)
    {
        Field wf = desc.getClass().getDeclaredField("workspaceFormat")
        wf.setAccessible(true) //Private field -- make it public
        wf.set(desc, required_format)
        wf.setAccessible(false) //And make it private again
    }
    

    This worked in Jenkins 2.122 with Subversion Plug-In 2.10.6