0
votes

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

1

1 Answers

1
votes

You missing some imports:

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

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