1

I would like to clean up the list of JDKs managed by our Jenkins CI server.

For instance there are several versions of JDK 8 whereas I'd like to only have one of them (the latest). So I am looking for a simple way for identifying all those Jenkins jobs explicitly using one of the other JDK installations so I can change them to use the one remaining JDK install.

Is there a better way to do so apart from manually clicking through all jobs and examine which JDK they use?

Jan
  • 13,738
  • 3
  • 30
  • 55
Gunnar
  • 18,095
  • 1
  • 53
  • 73

1 Answers1

1

I often use the Jenkins Script Console for tasks like this. The Groovy plugin provides the Script Console, but if you're going to use the Script Console for periodic maintenance, you'll also want the Scriptler plugin which allows you to manage the scripts that you run.

From Manage Jenkins -> Script Console, you can write a groovy script that iterates through the jobs:

for (job in Jenkins.instance.items) {
  println job.name
  ...examine more details of job...
}

It often takes some iteration to figure out the right set of job properties to examine. It's not clear to me how your jobs are configured, so you'll have to figure out what property describes the JDK used by the job. The Change JVM Options script might provide some hints.

As I describe in another answer, you can write functions to introspect the objects available to scripting. And so with some trial and error, develop a script that walks the list of jobs and examines the properties that you're interested in.

Community
  • 1
  • 1
Dave Bacher
  • 15,652
  • 3
  • 63
  • 86