Last active
June 3, 2020 09:52
-
-
Save scrain/6104ed52d9699c60df270f6cdb0df4cb to your computer and use it in GitHub Desktop.
Jenkins script to update the JDK for all jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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