'Pulling Artifactory Information From Jenkins Using DSL Script

Preface: I'm pretty green in the Jenkins\Artifactory\DSL space, so I'll prob sound like I'm bumbling along.

I'm working on a Jenkins DSL script to pull information on\about our Artifactory setup.

I don't have admin rights to Jenkins or Artifactory, just normal credentials to login and run things.

The Jenkins server has Artifactory credentials and the plugin is installed.

So my question goes...

I was using this snippet of code;

// Get Default Artifactory Info
import jenkins.model.*
def instance = Jenkins.get()
def defaultServer = Jenkins.instance.getDescriptor('org.jfrog.hudson.ArtifactoryBuilder').getArtifactoryServers()[0]
def defaultArtifactoryName = defaultServer.getName()
def defaultArtifactoryUrl = defaultServer.getUrl()
def defaultArtifactoryCredId = defaultServer.getDeployerCredentialsConfig().getCredentialsId()

To pull the info about our Artifactory server, to then pass as variables.

It used to work fine, but after an update (by our admins), it no longer works.

The error it throws in the Jenkins console is...

No signature of method: org.jfrog.hudson.ArtifactoryBuilder$DescriptorImpl.getArtifactoryServers() is applicable for argument types: () values: []

Could someone point me in the direction of any documentation as I've tried searching for the getArtifactoryServers method and can't seem to find anything.

Versions:

  • Jenkins 2.289.1
  • Artifactory Plugin 3.11.4
  • Job DSL 1.77

Thanks in advance!



Solution 1:[1]

Looks like you are running an internal Jenkins Artifactory plugin code.

getArtifactoryServers is recently changed to getJfrogInstances. I'm not sure what are you trying to do, but to get the same results as before, you should modify the script as following:

import jenkins.model.*
def instance = Jenkins.get()
def defaultServer = Jenkins.instance.getDescriptor('org.jfrog.hudson.ArtifactoryBuilder').getJfrogInstances()[0]
def jfrogInstanceId = defaultServer.getId()
def defaultArtifactoryUrl = defaultServer.getArtifactoryUrl()
def defaultArtifactoryCredId = defaultServer.getDeployerCredentialsConfig().getCredentialsId()

Solution 2:[2]

Thanks, this worked!

I figured it changed, I just couldn't find anything that said that it had or pointed me to what it changed to.

Would you happen to have a link to where I can read about all the methods\descriptors for getJfrogInstances?

I was looking here: https://javadoc.jenkins-ci.org/hudson/model/Descriptor.html

But they don't have the getArtifactoryUrl() one listed, so I'm guessing I'm looking in the wrong place.

Thanks again!

Solution 3:[3]

As @yahavi mentioned above, you shouldn't be using the plugin's code unless you are ok with your code/pipeline breaking when plugin gets updated.

You can use the DSL step getArtifactoryServer to get the information you want.

In Scripted pipeline:

script {
    def artifactoryServer = getArtifactoryServer 'jfrog_instance_id'
    // To see all properties (Please note that this might expose the credentials!)
    artifactoryServer.properties.each { println "$it.key -> $it.value" }
    // To get URL
    echo artifactoryServer.url
    // To get credentialsId
    echo artifactoryServer.credentialsId
    // etc...
}

In Declarative pipeline: You can't assign variables without script block in Declarative pipeline but to you can get the properties as String in Declarative pipeline. E.g., You can get the Artifactory URL using: ${getArtifactoryServer('jfrog_instance_id').url}

PS: jfrog_instance_id is the instance id given in Jenkins by your administrators. You should be able to ask them for the ID. Refer Configuring Jenkins Artifactory Plug-in

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yahavi
Solution 2 Thomas Lord
Solution 3 Praveen Lobo