通过Groovy脚本设置Artifactory Jenkins插件

时间:2017-06-12 10:21:13

标签: jenkins groovy artifactory

我正在尝试在初始化时通过Groovy脚本向Artkins添加Artifactory配置,但是我收到以下错误

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.jfrog.hudson.ArtifactoryServer(java.lang.String, java.lang.String, org.jfrog.hudson.util.Credentials, org.jfrog.hudson.util.Credentials, java.lang.Integer, java.lang.Boolean)

我正在运行的代码位于

之下

詹金斯版本:2.46.3 Artifactory插件版本:2.11.0

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 )
]

desc.setArtifactoryServers(sinst)

2 个答案:

答案 0 :(得分:2)

此外,我已经找到了使用凭据插件

执行此操作的方法
import java.lang.System
import hudson.model.*
import jenkins.model.*
import org.jfrog.*
import org.jfrog.hudson.*
import org.jfrog.hudson.util.Credentials;

def inst = Jenkins.getInstance()
def artifactoryDesc = inst.getDescriptor("org.jfrog.hudson.ArtifactoryBuilder")

CredentialsConfig deployerCredentials = new CredentialsConfig(new Credentials("credentialID", "credentialID"), "credentialID", false)

println "--> Configuring Artifactory... "
def ArtInst = [new ArtifactoryServer(
  "artifactiory",
  "https://servername:8443/artifactory",
  deployerCredentials,
  null,
  300,
  false,
  3 )
]

artifactoryDesc.setArtifactoryServers(ArtInst)
artifactoryDesc.setUseCredentialsPlugin(true)
artifactoryDesc.save()
println "--> Configuring Artifactory... done"

答案 1 :(得分:1)

我正在为同样的问题寻找解决方案,并想出来:

(?<=www\.)([^\.]+)