Disable all Jenkins jobs from a given Jenkins View / Tab

AKS picture AKS · Jun 29, 2015 · Viewed 7.3k times · Source

I have around 100-120 jobs in one of the view called "Gradle Deploys" that I created in Jenkins. How can I disable all the jobs from Jenkins only from a given View / tab.

I tried the following groovy syntax to first just show all the jobs in a given view but it errors out.

jenkins = Hudson.instance

//The following works actually but gives a lot of info.
//println "----" + jenkins.instance.getView("Gradle Deploys").items

println "----" + jenkins.instance.getView("Gradle Deploys").items.each.getItems().print(it)

Once I get the list of just job names in a given view, I just have to use ".disable()" function in the above command and it'll work.

If I use the following code, it does what I want, but I'm looking for a one liner.

for (item in jenkins.instance.getView("Gradle Deploys").items) {
   println("\nJob: $item.name")
   item.disabled=true

}  

Answer

tim_yates picture tim_yates · Jun 29, 2015

You should be able to just disable them all with:

jenkins.instance.getView("Gradle Deploys").items*.disabled = true

But if you want to print something out at the same time, you'll need an each

jenkins.instance.getView("Gradle Deploys").items.each { item ->
    println "\nJob: $item.name"
    item.disabled = true
}