forked from cloudbees/jenkins-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindAllGroupsInFolders.groovy
39 lines (34 loc) · 1.49 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
import nectar.plugins.rbac.groups.*
import com.cloudbees.hudson.plugins.folder.*
import com.cloudbees.jenkins.plugins.foldersplus.*
import com.cloudbees.hudson.plugins.folder.properties.FolderProxyGroupContainer
//Parent folder name to start with
String folderName = 'EmptyFolder'
folderItem = Jenkins.instance.getAllItems(Folder.class).find{it.name.equals(folderName)}
AbstractFolder < ? > folderAbs1 = AbstractFolder.class.cast(folderItem)
FolderProxyGroupContainer propertyFPG = folderAbs1.getProperties().get(FolderProxyGroupContainer.class)
print "Folder : " + folderItem.name + "\n"
findAllGroups(propertyFPG)
def findAllGroups(FolderProxyGroupContainer fpgc){
if (fpgc != null) {
fpgc.getGroups().findAll{it != null}.each {
println " Group : " + it.name
it.getGroupMembership().each{ println 'GroupMember : ' + it.name }
it.getMembers().each{ println ' Member : ' + it }
}
}
}
findAllItems(((com.cloudbees.hudson.plugins.folder.Folder) folderItem).getItems())
def findAllItems(items){
for(item in items)
{
if (item instanceof com.cloudbees.hudson.plugins.folder.Folder) {
AbstractFolder < ? > folderAbs1 = AbstractFolder.class.cast(item)
FolderProxyGroupContainer propertyFPG = folderAbs1.getProperties().get(FolderProxyGroupContainer.class);
println "Folder : " + item.name
findAllGroups(propertyFPG)
//Drill into folders
findAllItems(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems())
}
}
}