Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable all Jenkins jobs from a given Jenkins View / Tab

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

}  
like image 932
AKS Avatar asked Jun 29 '15 16:06

AKS


People also ask

How do I disable a view in Jenkins?

To delete this view, go to "Manage Jenkins" > "Configure System" and change the selection in the "Default View" drop-down. You can't change the default view unless you already have another view created. Once you have changed to a new default view, you can delete the "All" view.


1 Answers

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
}
like image 64
tim_yates Avatar answered Oct 02 '22 14:10

tim_yates