Hello,
if have created a groovy routine to replace values in a YAML document. If I run this as a groovy script or as a Jenkins FreeStyle Project things worked well. If I run this in Jenkins Pipeline Script the leaf element turns from java.util.LinkedHashMap$Entry to java.util.AbstractMap$SimpleImmutableEntry and setValue isn't available anymore. How can configure this behaviour? Do not find anything about this topic same jar sam code.
Thank you very much in advance.
Cheers Jochen
Yaml parser = new Yaml()
def deploymentYaml = parser.load(('file' as File).text)
replaceLeafValueInYAML(deploymentYaml, "Root", null, "namespace", "app-dev")
def replaceLeafValueInYAML(childs, position, nodename, argKey, argValue) {
if(nodename != null) {
position = position + "." + nodename
}
childs.each {element ->
def value = null
def key = null
if(element instanceof java.util.LinkedHashMap) {
value = element
} else if(element instanceof java.lang.String){
value = element
} else {
key = element.getKey();
value = element.getValue();
}
if(value instanceof java.util.LinkedHashMap) {
replaceLeafValueInYAML(value, position, key, argKey, argValue)
} else if(value instanceof java.util.ArrayList) {
replaceLeafValueInYAML(value, position, key + "[]", argKey, argValue)
} else {
def leafPosition = position + "." + key
if(leafPosition.endsWith(argKey)) {
println element.getClass()
element.setValue(argValue)
println "New value of key " + leafPosition + "=" + argValue
}
}
}
}
[Pipeline] End of Pipeline
java.lang.UnsupportedOperationException
at java.util.AbstractMap$SimpleImmutableEntry.setValue(AbstractMap.java:797)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCa