Skip to content

Instantly share code, notes, and snippets.

@scrain
Last active June 3, 2020 09:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scrain/6104ed52d9699c60df270f6cdb0df4cb to your computer and use it in GitHub Desktop.
Save scrain/6104ed52d9699c60df270f6cdb0df4cb to your computer and use it in GitHub Desktop.
Jenkins script to update the JDK for all jobs
import hudson.model.*
String newJdkName = "JDK 1.7.0_80"
boolean dryRun = true
def h = Hudson.getInstance()
Set jdks = new HashSet()
def newJdk = h.getJDK(newJdkName)
assert newJdk, "unable to find a configured jdk named ${newJdkName}"
println "reconfiguring all jobs to use jdk '${newJdkName}'"
for (item in h.items) {
if ( item instanceof com.cloudbees.hudson.plugins.folder.Folder ) {
continue
}
if ( item.JDK?.name != newJdkName ) {
println "\t job '${item.name}' current jdk '${item.JDK?.name}'"
if (!dryRun) {
item.setJDK(newJdk)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment