Last active
September 19, 2016 13:48
-
-
Save matthiasbaldi/22e028b023f98d91d82fbd6f813cbed9 to your computer and use it in GitHub Desktop.
This file contains 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
// this script can be used to change the JDK for multiple Jenkins Jobs | |
// to use the script, edit the variables and run it in the Jenkins Script Console | |
// please set the variable value | |
def jobNameWithCorrectJdk = "" // set a JobName with the correct JDK | |
def jdkToChange = "JDK[JDK 1.8]" // set the JDK you want to change | |
def partOfJobNameToSearch = "" // set a part of the job name to generate the list of jobs | |
// script - here you have nothing to edit | |
def newJdk = Jenkins.instance.getItemByFullName(jobNameWithCorrectJdk).JDK | |
def totCounter = 0 | |
def okCounter = 0 | |
def badCounter = 0 | |
for (item in Jenkins.instance.items) { | |
name = item.name | |
if (name.toLowerCase().contains(partOfJobNameToSearch.toLowerCase())) { | |
totCounter++ | |
println("---------------------------------") | |
if (item.getJDK().toString().contains(jdkToChange)) { | |
println("[INFO] change JDK: " + item.name) | |
println("--> old JDK: " + item.getJDK()) | |
item.setJDK(newJdk) | |
if (item.getJDK().toString().contains(newJdk.toString())) { | |
println("JDK change successful") | |
okCounter++ | |
} else { | |
println("[ERROR] JDK change not successful:") | |
println("--> " + item.name) | |
println("--> " + item.getJDK()) | |
badCounter++ | |
} | |
} else { | |
println("[INFO] no JDK change required: " + item.name) | |
} | |
} | |
} | |
println("---------------------------------") | |
println(totCounter + " total items") | |
println(okCounter + " items with status successful :)") | |
println(badCounter + " items with status failure :(") | |
println((totCounter - badCounter - okCounter) + " items with no change") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment