简体   繁体   English

如何在 Jenkins 中使用 Groovy 脚本设置颠覆工作区格式?

[英]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 ).我正在尝试以编程方式( Img )更改 SubversionSCM 插件的 Subversion 工作区格式。 Naturally, I've been trying with a groovy script, but I cannot find any method of doing so.当然,我一直在尝试使用 groovy 脚本,但我找不到任何这样做的方法。

I was able to retrieve the current format by running this script in a Groovy console:通过在 Groovy 控制台中运行此脚本,我能够检索当前格式:

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.这将打印出正确的 31。 It is the value of the "WC_FORMAT_18" member found in the interface "ISVNWCDb" interface of "svnkit".它是在“svnkit”的“ISVNWCDb”接口中找到的“WC_FORMAT_18”成员的值。 You can see it being used in the git repository of the plugin here .你可以在这里看到它在插件的 git 存储库中使用。

Searching the documentation of subversion plugin I could not find any method of setting it, nor any public method in the SubversionSCM descriptor .搜索 subversion 插件的文档,我找不到任何设置它的方法,也找不到SubversionSCM 描述符中的任何公共方法。

Is there any way of configuring that setting programmatically.有没有办法以编程方式配置该设置。 I would prefer a groovy script, but at the moment anything would do.我更喜欢 groovy 脚本,但目前任何事情都可以。

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.正如您已经发现的那样,SubversionSCM 描述符上没有工作区格式的设置器,但工作区格式作为私有字段存在。

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这在 Jenkins 2.122 和 Subversion Plug-In 2.10.6 中有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM