Skip to content

Instantly share code, notes, and snippets.

@matthiasbaldi
Last active September 19, 2016 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthiasbaldi/22e028b023f98d91d82fbd6f813cbed9 to your computer and use it in GitHub Desktop.
Save matthiasbaldi/22e028b023f98d91d82fbd6f813cbed9 to your computer and use it in GitHub Desktop.
// 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