-
Notifications
You must be signed in to change notification settings - Fork 412
/
copyGrpsBetweenNodes.groovy
48 lines (42 loc) · 1.69 KB
/
copyGrpsBetweenNodes.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
44
45
46
47
48
import nectar.plugins.rbac.*
import hudson.model.*
import hudson.slaves.*
import nectar.plugins.rbac.groups.NodeProxyGroupContainer
//Simple script to copy groups and roles from a source Node to a destination Node.
String name1 = 'Source_Node_name'
String name2 = 'Destination_Node_name'
Node nodeAbs1 = Jenkins.instanceOrNull.getNode(name1)
Node nodeAbs2 = Jenkins.instance.nodes.find{it.name.equals(name2)}
println nodeAbs1
println nodeAbs2
if(nodeAbs1 == null || nodeAbs2 == null){
println 'Nodes not found'
} else {
NodeProxyGroupContainer propertyNodeProxyGroup1 = nodeAbs1.getNodeProperties().get(NodeProxyGroupContainer.class);
NodeProxyGroupContainer propertyNodeProxyGroup2 = nodeAbs2.getNodeProperties().get(NodeProxyGroupContainer.class);
if (propertyNodeProxyGroup2 == null) {
NodeProxyGroupContainer c = new NodeProxyGroupContainer()
nodeAbs2.getNodeProperties().add(c)
//c.owner=nodeAbs2
propertyNodeProxyGroup2 = nodeAbs2.getNodeProperties().get(NodeProxyGroupContainer.class)
}
println "propertyNodeProxyGroup2 : " + propertyNodeProxyGroup2
println "propertyNodeProxyGroup1 : " + propertyNodeProxyGroup1
if (propertyNodeProxyGroup1 != null) {
propertyNodeProxyGroup1.getGroups().findAll{it != null}.each {
try{
propertyNodeProxyGroup2.addGroup(it)}
catch(Exception ex){
println "Exception----------"
println ex
}
println "Group : " + it
}
propertyNodeProxyGroup1.getRoleFilters().findAll{it != null}.each {
println "RoleFilter : " + it
propertyNodeProxyGroup2.addRoleFilter(it)
}
println "Saving..."
nodeAbs2.save()
}
}