在groovy中使用缩进合并基于两个的yaml



我正在尝试合并jenkins文件(.Jenkinsfile(中的两个yaml

def runConf = """
fail_fast: false
tests:
- ABC:
"""
print(runConf)
def defaultRunConfig = """
test:
- ABC.json
- DEF.json
Seconds: 60
Type: dynamic
"""
def runConfigObj
runConfigObj = readYaml([text:defaultRunConfig])
String time = defaultRunConfig.Seconds.toString()
echo ("Duration for run: " +time)
def runConfigBase
runConfigBase = readYaml([text:runConf])
Map<Object, Object> runConfiguration = [:]
runConfiguration.putAll(runConfigBase)
print(runConfiguration)
for (tests in runConfigObj.test) {
print(runConfigObj.test)
runConfiguration.put(runConfigObj.test)
}
runConfiguration['Seconds'] = runConfigObj.Seconds.toString()
runConfiguration['Type'] = runConfigObj.Type

期望得到这样的东西:

fail_fast: false
tests:
- ABC:
test:
- ABC.json
- DEF.json
Seconds: 60
Type: dynamic

但我得到以下错误:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.LinkedHashMap.put() is applicable for argument types: (java.util.ArrayList) values: 

尝试在groovy中查找MAP等选项,但无法解决问题

如何避免这样的错误?我是groovy的新手,任何帮助都非常感谢

所以您想要添加一个"测试";作为键test的值到runConfiguration的映射对象中,那么它应该是这样的:

runConfiguration['test']=[]
for (test in runConfigObj) {
runConfiguration['test'].add(test)
}

最新更新