我正在尝试使用Groovy在Jenkins中编写插件的配置脚本。某些插件(例如GitHub Pull Request
Builder插件)并未提供任何简单的方法来在Jenkins
Web界面(使用名为Stapler的库将HTML表单绑定到对象实例)之外配置插件。
`Stabl
但是,我不能说服Groovy强迫null或NullObject作为的第一个论点configure(request, formData)。
Groovy可以这样做吗?
import org.codehaus.groovy.runtime.NullObject
def descriptor = org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl
net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject() as net.sf.json.JSONObject;
org.kohsuke.stapler.StaplerRequest stapler = NullObject as org.kohsuke.stapler.StaplerRequest
println ("Is it a stapler request? ${stapler instanceof org.kohsuke.stapler.StaplerRequest}.")
println descriptor.configure(stapler, jsonObject)
输出:
Is it a stapler request? true.
groovy.lang.MissingMethodException: No signature of method: static org.jenkinsci.plugins.ghprb.GhprbTrigger$DescriptorImpl.configure() is applicable for argument types: (Class_delegateProxy, net.sf.json.JSONObject) values: [Class_delegateProxy@31433174, [:]]
Possible solutions: configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject), configure(org.kohsuke.stapler.StaplerRequest, net.sf.json.JSONObject), configure(org.kohsuke.stapler.StaplerRequest)
更新资料
因此,詹金斯(Jenkins)的API可能非常复杂,有时并不明显。我对静态DescriptorImpl类型的引用是错误的。我仍然很想知道以上原因为何失败。
def descriptor = jenkins.model.Jenkins.getInstance().getDescriptorByType(org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl.class)
//def plugin = org.jenkinsci.plugins.ghprb.GhprbTrigger.DescriptorImpl
net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject();
org.kohsuke.stapler.StaplerRequest stapler = null
println ("Is it a stapler request? ${stapler instanceof org.kohsuke.stapler.StaplerRequest}.")
jsonObject.put("serverAPIUrl", "https://api.github.com");
jsonObject.put("username", "user");
jsonObject.put("password", "1111");
jsonObject.put("accessToken", "accessToken");
jsonObject.put("adminlist", "user");
jsonObject.put("allowMembersOfWhitelistedOrgsAsAdmin", "false");
jsonObject.put("publishedURL", "");
jsonObject.put("requestForTestingPhrase", "test this");
jsonObject.put("whitelistPhrase", "");
jsonObject.put("okToTestPhrase", "ok to test");
jsonObject.put("retestPhrase", "retest this please");
jsonObject.put("skipBuildPhrase", "[skip ci]");
jsonObject.put("cron", "*/1 * * * *");
jsonObject.put("useComments", "true");
jsonObject.put("logExcerptLines", "0");
jsonObject.put("unstableAs", "");
jsonObject.put("testMode", "true");
jsonObject.put("autoCloseFailedPullRequests", "false");
jsonObject.put("msgSuccess", "Success");
jsonObject.put("msgFailure", "Failure");
println descriptor.configure(stapler, jsonObject)
输出量
Is it a stapler request? false.
true