-
Notifications
You must be signed in to change notification settings - Fork 411
/
FindAllGroupsInFolders.groovy
43 lines (37 loc) · 1.36 KB
/
FindAllGroupsInFolders.groovy
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import com.cloudbees.hudson.plugins.folder.AbstractFolder
import nectar.plugins.rbac.groups.GroupContainer
import nectar.plugins.rbac.groups.GroupContainerLocator
//Parent folder name to start with
String folderName = 'EmptyFolder'
AbstractFolder folderItem = Jenkins.instance.getAllItems(AbstractFolder.class).find{ (it.name == folderName) }
print "Folder : " + folderItem.name + "\n"
GroupContainer container = GroupContainerLocator.locate(folderItem);
findAllGroups(container)
def findAllGroups(GroupContainer fpgc) {
if (fpgc != null) {
fpgc.getGroups().findAll { it != null }.each {
println " Group: " + it.name
println ' Memberships: '
// For RBAC Plugin < 5.66, use the following
// it.getMembers().each{ println ' Member : ' + it }
// For RBAC Plugin 5.66 or later, use the following
it.getUsers().each { println ' User: ' + it }
it.getGroups().each { println ' Group: ' + it }
it.getMembers().each { println ' Ambiguous Member: ' + it }
}
}
}
findAllItems(folderItem.getItems())
def findAllItems(items){
for(item in items)
{
if (item instanceof AbstractFolder) {
GroupContainer container = GroupContainerLocator.locate(item);
println "Folder: " + item.name
findAllGroups(container)
//Drill into folders
findAllItems(((AbstractFolder) item).getItems())
}
}
}
return