无法使用groovy脚本在jenkins中配置artifactory

时间:2017-09-08 16:56:51

标签: jenkins groovy

我试图使用groovy init脚本在Jenkins中配置artifactory,这是我正在尝试执行的脚本

import jenkins.model.*
import org.jfrog.*
import org.jfrog.hudson.*
import org.jfrog.hudson.util.Credentials;

def inst = Jenkins.getInstance()

def desc = inst.getDescriptor("org.jfrog.hudson.ArtifactoryBuilder")

def deployerCredentials = new Credentials("admin", "password")
def resolverCredentials = new Credentials("", "")

def sinst = [new ArtifactoryServer(
 "server-id",
"http://localhost:8081/artifactory",
deployerCredentials,
resolverCredentials,
 300,
 false,
 false,
 false,
 1)
]
desc.setArtifactoryServers(sinst)
desc.save()

但是我收到了以下错误

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.jfrog.hudson.CredentialsConfig(java.lang.String, java.lang.String)
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 org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
at Script1.run(Script1.groovy:17)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:142)
at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:114)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at hudson.util.RemotingDiagnostics.executeGroovy(RemotingDiagnostics.java:111)
at jenkins.model.Jenkins._doScript(Jenkins.java:4350)
at jenkins.model.Jenkins.doScriptText(Jenkins.java:4328)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:343)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:184)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:117)
at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:129)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:715)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:845)
at org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)
at org.kohsuke.stapler.Stapler.service(Stapler.java:238)

如果有人能帮助我解决这个问题,那就太棒了。

1 个答案:

答案 0 :(得分:1)

这个对我有用

//artifactory
import jenkins.model.*
import org.jfrog.*
import org.jfrog.hudson.*
import org.jfrog.hudson.util.Credentials;

inst = Jenkins.getInstance()
desc = inst.getDescriptor("org.jfrog.hudson.ArtifactoryBuilder")
deployerCredentials = new CredentialsConfig("user", "password","1",true)    
sinst = [new ArtifactoryServer(
  "1",
  "https://artifactory-url/",
  deployerCredentials,
  null,
  300,
  false ,
  3)]

desc.setUseCredentialsPlugin(false)
desc.setArtifactoryServers(sinst)
desc.save()