-
Notifications
You must be signed in to change notification settings - Fork 1
/
copyRestrictionsBetweenFolders.groovy
35 lines (28 loc) · 1.49 KB
/
copyRestrictionsBetweenFolders.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
import com.cloudbees.hudson.plugins.folder.*
import com.cloudbees.jenkins.plugins.foldersplus.*
import com.cloudbees.hudson.plugins.folder.properties.FolderProxyGroupContainer
import com.cloudbees.hudson.plugins.folder.properties.SubItemFilterProperty
String source = 'sub folder'
String destination = 'z'
AbstractFolder < ? > folderAbs1 = AbstractFolder.class.cast(Jenkins.instance.getAllItems(Folder.class).find{it.name.equals(source)})
AbstractFolder < ? > folderAbs2 = AbstractFolder.class.cast(Jenkins.instance.getAllItems(Folder.class).find{it.name.equals(destination)})
if(folderAbs1 == null || folderAbs2 == null){
println 'folders not found'
} else {
println folderAbs2
SubItemFilterProperty propertyFPG1 = folderAbs1.getProperties().get(SubItemFilterProperty.class);
folderAbs2.getItems().findAll{it instanceof Folder}.each { folderChild ->
SubItemFilterProperty propertyFPG2 = folderChild.getProperties().get(SubItemFilterProperty.class);
if (propertyFPG2 == null || propertyFPG2.allowedTypes == null) {
SubItemFilterProperty c = new SubItemFilterProperty(new ArrayList<String>())
folderChild.getProperties().replace(c)
c.owner=folderChild
propertyFPG2 = folderChild.getProperties().get(SubItemFilterProperty.class)
}
println "propertyFPG2 : " + propertyFPG2
println "propertyFPG1 : " + propertyFPG1
if (propertyFPG1 != null && propertyFPG1.allowedTypes != null) {
propertyFPG2.allowedTypes.addAll(propertyFPG1.allowedTypes)
}
}
}