Patris
Patris

Reputation: 83

Jenkins: Accessing other plugins from Active Choices Parameter groovy script

I'm quite new to Jenkins, Groovy and all that, so forgive me if this sounds dumb. I'm using the Active Choices plugin, and from one of the AC Parameters inside the Groovy script I want to use a different plugin - Artifactory, to fetch a file and display each line inside it as an option.

try {
    def server = Artifactory.newServer url: 'http://localhost:8081/artifactory/', username: 'user', password: 'pass'    
    def downloadSpec = """{
        "files": [
            {
                "pattern": "example-repo-local/file.txt",
                "target": "example/"
            }
        ]
    }"""
    server.download(downloadSpec)

    String text = readFile("example/file.txt")
    return text.tokenize("\n")
} catch (Exception e) {
    return [e]
}

However, the Active Choices Parameter doesn't seem to recognize other plugins, and it can't find the Artifactory property:

groovy.lang.MissingPropertyException: No such property: Artifactory for class: Script1

My question is - do I need to import the plugin somehow? If so, how do I determine what to import?

There is an option to also specify an "Additional classpath" near an Active Choice Parameter, but the plugin contains 75 jar files in its WEB-INF/lib directory. (just specifying the artifactory.jar one doesn't seem to change anything)

Just a note - the Pipeline recognizes the Artifactory plugin and it works fine - I can successfully connect and retreive a file and read it.

Upvotes: 2

Views: 2678

Answers (1)

3sky
3sky

Reputation: 890

I can't fine any possibility to run Artifactory plugin in reasonable way. So i thing better option is use curl, and Artifactory API. For example my Active Choices Parameter based on Json file from Artifactory;

import groovy.json.JsonSlurper
def choices = []
def response = ["curl", "-k", "https://artifactory/app/file.json"].execute().text
def list = new JsonSlurper().parseText( response )
list.each { choices.push(it.name) }
return choices 

Upvotes: 0

Related Questions