-
Notifications
You must be signed in to change notification settings - Fork 417
Expand file tree
/
Copy pathdisableJobsInFolder.groovy
More file actions
29 lines (24 loc) · 976 Bytes
/
disableJobsInFolder.groovy
File metadata and controls
29 lines (24 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*** BEGIN META {
"name" : "Disable All Jobs In Folder",
"comment" : "Disable all the buildable projects inside a Folder (full name must be provided)",
"parameters" : [ 'folderFullName' ],
"core": "1.609",
"authors" : [
{ name : "Allan Burdajewicz" }
]
} END META**/
import com.cloudbees.hudson.plugins.folder.AbstractFolder
import hudson.model.AbstractProject
import jenkins.model.Jenkins
// I want to disable jobs
def disableJobs = { println "Disabling '${it.fullName}'"; it.disable() }
//Function to retrieve all buildable Project in a specific Folder
def doAllItemsInFolder(folderName, closure) {
AbstractFolder folder = Jenkins.instance.getAllItems(AbstractFolder.class)
.find {folder -> folderName == folder.fullName };
folder.getAllJobs()
.findAll {job -> job instanceof AbstractProject}
.findAll {job -> job.isBuildable()}
.each {closure(it)};
}
doAllItemsInFolder("${folderFullName}", disableJobs);