1
+ import com.cloudbees.hudson.plugins.folder.*
2
+ import com.cloudbees.jenkins.plugins.foldersplus.*
3
+ import com.cloudbees.hudson.plugins.folder.properties.FolderProxyGroupContainer
4
+
5
+ String name1 = ' test'
6
+ String name2 = ' test2'
7
+
8
+
9
+ AbstractFolder < ? > folderAbs1 = AbstractFolder . class. cast(Jenkins . instance. getAllItems(Folder . class). find{it. name. equals(name1)})
10
+ AbstractFolder < ? > folderAbs2 = AbstractFolder . class. cast(Jenkins . instance. getAllItems(Folder . class). find{it. name. equals(name2)})
11
+
12
+ if (folderAbs1 == null || folderAbs2 == null ){
13
+ println ' folders not found'
14
+ } else {
15
+ /*
16
+ // CloudBess Folder > 5.2.2
17
+ SecurityGrantsFolderProperty property1 = SecurityGrantsFolderProperty.of(folderAbs1)
18
+ SecurityGrantsFolderProperty property2 = SecurityGrantsFolderProperty.of(folderAbs2,true)
19
+
20
+ println "property2 : " + property2
21
+ println "property1 : " + property1
22
+ if (property1 != null) {
23
+ property1.getSecurityGrants().each {
24
+ println "SecurityGrant : " + it
25
+ property2.addSecurityGrant(it)
26
+ }
27
+ }
28
+
29
+ */
30
+ // CloudBees Folder <=5.2.2
31
+ FolderProxyGroupContainer propertyFPG1 = folderAbs1. getProperties(). get(FolderProxyGroupContainer . class);
32
+ FolderProxyGroupContainer propertyFPG2 = folderAbs2. getProperties(). get(FolderProxyGroupContainer . class);
33
+
34
+ if (propertyFPG2 == null ) {
35
+ FolderProxyGroupContainer c = new FolderProxyGroupContainer ()
36
+ folderAbs2. getProperties(). replace(c)
37
+ c. owner= folderAbs2
38
+ propertyFPG2 = folderAbs2. getProperties(). get(FolderProxyGroupContainer . class)
39
+ }
40
+
41
+ println " propertyFPG2 : " + propertyFPG2
42
+ println " propertyFPG1 : " + propertyFPG1
43
+ if (propertyFPG1 != null ) {
44
+ propertyFPG1. getGroups(). findAll{it != null }. each {
45
+ println " Group : " + it
46
+ propertyFPG2. addGroup(it)
47
+ }
48
+ propertyFPG1. getRoleFilters(). findAll{it != null }. each {
49
+ println " RoleFilter : " + it
50
+ propertyFPG2. addRoleFilter(it)
51
+ }
52
+ propertyFPG2. save()
53
+ }
54
+ }
0 commit comments