我正在尝试通过groovy脚本配置Jenkins Jira插件,但收到错误
WARNING: Failed to run script file:/var/jenkins_home/init.groovy.d/k_JiraPluginConfig.groovy
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: hudson.plugins.jira.JiraSite(java.net.URL, java.net.URL, java.lang.String, java.lang.String, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, null, null, java.lang.Boolean)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1732)
at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1532)
at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at k_JiraPluginConfig.run(k_JiraPluginConfig.groovy:13)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:136)
at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:127)
at jenkins.util.groovy.GroovyHookScript.run(GroovyHookScript.java:110)
at hudson.init.impl.GroovyInitScript.init(GroovyInitScript.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:282)
at jenkins.model.Jenkins$5.runTask(Jenkins.java:1065)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:210)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
这是我的groovy脚本看起来像
import hudson.plugins.jira.JiraProjectProperty
import hudson.plugins.jira.JiraSite
import jenkins.model.*
def env = System.getenv()
def jenkins = Jenkins.getInstance()
JiraProjectProperty.DescriptorImpl config = jenkins.getExtensionList(JiraProjectProperty.DescriptorImpl.class)[0]
JiraSite jiraSite = new JiraSite(new URL(env.JIRA_URL),
new URL(env.JIRA_URL),
env.JIRA_USERNAME,
env.JIRA_PASSWORD,
true,
true,
true,
null, null, false)
jiraSite.setDisableChangelogAnnotations(false)
jiraSite.setTimeout(10)
jiraSite.setDateTimePattern('EEE, d MMM yyyy HH:mm:ss Z')
jiraSite.setAppendChangeTimestamp(true)
config.setSites(jiraSite)
config.save()
这段代码我从Jira-plugin的配置文件派生而来,XML文件如下所示
<?xml version='1.0' encoding='UTF-8'?>
<hudson.plugins.jira.JiraProjectProperty_-DescriptorImpl plugin="jira@2.5">
<sites>
<hudson.plugins.jira.JiraSite>
<url>https://jira.mycompany.com/</url>
<useHTTPAuth>false</useHTTPAuth>
<userName>Jenkins</userName>
<password>{secretPassword}</password>
<supportsWikiStyleComment>true</supportsWikiStyleComment>
<recordScmChanges>true</recordScmChanges>
<disableChangelogAnnotations>false</disableChangelogAnnotations>
<updateJiraIssueForAllStatus>true</updateJiraIssueForAllStatus>
<timeout>10</timeout>
<dateTimePattern></dateTimePattern>
<appendChangeTimestamp>true</appendChangeTimestamp>
</hudson.plugins.jira.JiraSite>
</sites>
</hudson.plugins.jira.JiraProjectProperty_-DescriptorImpl>
不确定我在这里缺少什么,任何帮助都会很明显。
其他详情
Jenkins版本 - 2.9.3
Jira版本 - 7.2.2
Jira-Plugin版本 - 2.5
Jira-Plugin repo - https://github.com/jenkinsci/jira-plugin
提前致谢
答案 0 :(得分:2)
您需要查看JiraSite Constructor并在groovy脚本中更新JiraSite构造函数调用以匹配它。 JiraSite的构造函数如下所示
JiraSite(URL url, URL alternativeUrl,
String userName, String password,
boolean supportsWikiStyleComment, boolean recordScmChanges,
String userPattern, boolean updateJiraIssueForAllStatus,
String groupVisibility, String roleVisibility,
boolean useHTTPAuth)
因此,基于构造函数签名,您需要在groovy脚本中更新构造函数调用,如下所示:
JiraSite jiraSite = new JiraSite(new URL(env.JIRA_URL), new URL(env.JIRA_URL),
env.JIRA_USERNAME, env.JIRA_PASSWORD,
true, true,
null, true,
null, null,
false)
我假设不需要userPattern,因此将其作为null,您可以根据需要更新它。这是你在构造函数调用中错过的论点
希望这有帮助