SGDave
SGDave

Reputation: 119

Jenkins Extensible Choice Plugin System Groovy Choice Parameter not working

I am hoping to use a Groovy script that generates a list of jobs on a Jenkins instance as a build parameter. The script works in Jenkins' Script Console: enter image description here
but does not work in the job: enter image description here
I get the same result if I import any of jenkins.*, jenkins.model.*, hudson.*, or hudson.model.* into the script, as referenced in the Script Console.
When I try to test the script in Configure, I am unable to with or without using the Groovy Sandbox. What am I missing? Thanks in advance.
enter image description here
enter image description here

Upvotes: 0

Views: 1018

Answers (1)

Sers
Sers

Reputation: 12255

You missing some imports:

import jenkins.model.*
import hudson.model.*

jobNames = []
Jenkins.instance.getAllItems(Job.class).each{ 
    jobNames.add(it.name.toString())
}
return jobNames

Upvotes: 1

Related Questions