Groovy custom sort a map by value
To sort with case insensitive, use
m.sort { it.value.toLowerCase() }
Assuming you mean you want to sort on value, you can just do:
Map m =[ james :"silly boy",
janny :"Crazy girl",
jimmy :"funny man",
georges:"massive fella" ]
Map sorted = m.sort { a, b -> a.value <=> b.value }
If somebody is looking for how to make it work in the Jenkins pipeline script, you will have to create a separate method with @NonCPS
annotation for that:
@NonCPS
def getSorted(def mapSizeMap){
mapSizeMap.sort(){ a, b -> b.value <=> a.value }
}
And then call it from the pipeline script.
def sortedMapZoneMap = getSorted(mapZonesMap)
You can of course apply "case sensitive" logic on top.