繁体   English   中英

Groovy map,获取,变量,Jenkins

[英]Groovy map, get, variable, Jenkins

我在 Groovy 中的映射有问题。 我想获得一个基于变量的值。

def function(){
    map = [
         'test1': '1234',
         'test2': '4567'
    ]
    var=test1
    def result = map.get.("$var")
    return result
}

但不幸的是。 我总是回来:

无法在 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.

你只想要map[var]

  • 下面更新了 BalRog 的注释

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM