简体   繁体   中英

Setting up Artifactory Jenkins plugin via Groovy scripts

I am trying to add Artifactory configuration to Jenkins via a Groovy script upon initialization, however I get the following error

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)

The code I am running is below

Jenkins version: 2.46.3 Artifactory Plugin Version: 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)

Additionally I have found a way of doing this using the credentials plugin

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"

I was searching for a solution for the same problem, and figured this out:

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 CredentialsConfig("admin", "password", "")
def resolverCredentials = new CredentialsConfig("", "", "")

def sinst = [new ArtifactoryServer(
  "main",
  "http://localhost:8081/artifactory",
  deployerCredentials,
  resolverCredentials,
  300,
  false,
  3 )
]

desc.setArtifactoryServers(sinst)

desc.save()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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