I am parsing the below xml content using the XmlParser class in groovy.
The content of xml is as follows:
<root><element1 attribute1="value1">Text content of element1</element1></root> And trying to retrieve the text content of the first child node of root node, like this:
output.element1.text() where, output is the result after parsing the xml content using XmlParser.
Completed code snippet I am running is as follows:
def parser = new XmlParser() def xmlContent = '<root><element1 attribute1="value1">Text content of element1</element1></root>' def output = parser.parseText(xmlContent) script.echo(output.element1.text()) It works fine in my local and gives expected output of script.echo as 'Text content of element1'
However, when I executed this in Jenkins groovy pipeline job, I get the following:
groovy.lang.MissingPropertyException: No such field found: field groovy.util.Node element1 I compared the versions of groovy and java with the version used in Jenkins. But it's the same version.
In my local:
- Groovy version - 2.4.21
- Java version - 11
In Jenkins:
- Groovy version - 2.4.21
- Java version - 11
- Jenkins version - 2.375.1
Do you know what might be the reason for such behavior in Jenkins with XmlParser? How to overcome this?
@NonCPSdecorator just above your function call? (see: jenkins.io/doc/book/pipeline/cps-method-mismatches)