[英]Groovy map, get, variable, Jenkins
I have a problem with mapping in Groovy.我在 Groovy 中的映射有问题。 I would like to get a value based on a variable.
我想获得一个基于变量的值。
def function(){
map = [
'test1': '1234',
'test2': '4567'
]
var=test1
def result = map.get.("$var")
return result
}
But, unfortunately.但不幸的是。 I always get back:
我总是回来:
Cannot get property '[test1]' on null object
无法在 null object 上获取属性“[test1]”
You are making a HashMap behind the scenes here and the way you are accessing it map.get.["$var"]
Groovy is trying to access a key called "get" on your variable map. You are making a HashMap behind the scenes here and the way you are accessing it
map.get.["$var"]
Groovy is trying to access a key called "get" on your variable map.
You just want map[var]
你只想要
map[var]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.