Remove keys from multilevel map in Jenkins groovy

118 views
Skip to first unread message

viraj

unread,
Sep 7, 2018, 4:02:58 AM9/7/18
to Jenkins Users
I have multilevel map like :

def someMap = [gen:[type:all], 
 build
:[time:6,
    types
:[
     
TypeA:[type1:[a:true, b:false, c:true, d:true, e:true],
             type2
:[a:true, b:false, c:true, d:true, e:true]],
     
TypeB:[type1:[a:true, b:false, c:true, d:true, e:true]
             type2
:[a:true, b:false, c:true, d:true, e:true]],
     
TypeC:[type1:[a:true, b:false, c:true, d:true, e:true],
             type2
:[a:true, b:false, c:true, d:true, e:true]]]]

 I want to remove the some entries from it, say "TypeA" and "TypeB" from map but with Jenkins groovy script I am not able to do so, with normal groovy, i can delete entries with removeAll() or with iterator, Below things already tried.

someMap.build.types.keySet().removeAll(['TypeA', 'TypeB', 'TypeC'].minus('TypeC')))
def iterator = someMap.build.types.entrySet().iterator()
while (iterator.hasNext()) {
 
if (iterator.next().key != 'TypeC' ) {
    iterator
.remove()
 
}
}

but i get the original map with no element removed.



Reply all
Reply to author
Forward
0 new messages