Last active
November 1, 2019 22:02
-
-
Save scrain/37a532b37ff59e81fe333be06ef21933 to your computer and use it in GitHub Desktop.
Script to update all Jenkins jobs using old JDK to new JDK
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
String oldJdkName = "JDK 1.7.0_80" | |
String newJdkName = "JDK 1.8.202" | |
boolean dryRun = true | |
Set jdks = new HashSet() | |
def newJdk = Jenkins.instance.getJDK(newJdkName) | |
assert newJdk, "unable to find a configured jdk named ${newJdkName}" | |
println "reconfiguring all jobs using ${oldJdkName} to use jdk '${newJdkName}'" | |
for (item in Jenkins.instance.getAllItems(Job.class).findAll{it.hasProperty('JDK')}) { | |
if ( oldJdkName == item.JDK?.name ) { | |
println "\t job '${item.name}' current jdk '${item.JDK?.name}', changing to ${newJdkName}" | |
if (!dryRun) { | |
item.setJDK(newJdk) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment