使用 groovy,如何在另一个数组变量中替换数组的值?
例如:
def Env = [
'Env1',
'Env2',
'Env3'
]
def Job = [
[
name: "Job1",
label: "<$Env>",
action: #!/usr/bin/bash
blah
blah
],
[
name: "Job2",
label: "<$Env>",
action: #!/usr/bin/bash
blah
blah
]
]
我希望第二个数组作业中的标签字段由 Env 中的每个项目填充
如果代码不是动态的,你可以做:
def Env = ['Env1','Env2', 'Env3']
def Job = [
[
name: "Job1",
label: "<${Env[0]}>",
action: '#!/usr/bin/bash'
],
[
name: "Job2",
label: "<${Env[1]}>",
action: '#!/usr/bin/bash'
]
]
如果它是动态的,你可以做:
Job.eachWithIndex{ obj, idx ->
obj.label = Env[idx]
}