Disable all Jenkins jobs from a given Jenkins View / Tab Disable all Jenkins jobs from a given Jenkins View / Tab jenkins jenkins

Disable all Jenkins jobs from a given Jenkins View / Tab


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}


Thanks to Tim for his solution. I'm adding/enhancing it a bit further:

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 = Hudson.instance    jenkins.instance.getView("Gradle Deploys").items.each { item ->    println "\nJob: $item.name"    item.disabled = true}

Now, the above examples works perfectly if you try to run them from "Script Console" but it errors out if you try to create/run it as a Scriptler script (as shown below).

See: The above code works in Script Console view in Jenkins (When you click Manage Jenkins > Script Console). To get this, you may need the plugin installed.

enter image description here

Now, the same script didn't work when I tried to create a Scripter Script and ran it that way. This requires Scriptler Plugin installed.

enter image description here

To Solve the above error message (as shown in the Scriptler Script - window), you need to enter another line (at top).

Final script looks like (NOTE: Value of viewName variable will be provided by the Scriptler parameter and it'll overwrite whatever you'll mention in the script itself):

//The following line is necessary if you are running the script/code via a "Scriptler Script" script way.//This way you can prompt a user to provide parameters (for ex: viewName) and use it to disable job in that view only.

import hudson.model.*jenkins = Hudson.instanceprintln ""println "--- Disabling all jobs in view: ${viewName}"println ""jenkins.instance.getView(viewName).items*.disabled = true//Now the above will disable it but you still need to save it. Otherwise, you'll loose your changes (of disabling the jobs) after each Jenkins restart.jenkins.instance.getView(viewName).items.each { item -> item.save() }


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