Jenkins XmlParser reports No such field found for attribute for root node Jenkins XmlParser reports No such field found for attribute for root node jenkins jenkins

Jenkins XmlParser reports No such field found for attribute for root node


Edit:

I tested some more in context of being able to also modify the attribute, and found out when using the [] access, the @ selector for attributes actually works. It seems this leads to use different methods under the hood which you can approve in jenkins (getAtand putAt) .

We can simply use

def rootNode = new XmlParser().parseText(xml)println rootNode['@version']

Original Answer:

There seems some bug regarding the direct access to the attributes with the @ selector on the groovy.util.Node object with the script sandbox.

A workaround is to use the .attributes() method to get the full Map of attributes, and access the value via the key like the following:

def rootNode = new XmlParser().parseText(xml)println rootNode.attributes()['version']

This will fail the first run and promt you to approve the use of method groovy.util.Node attributes, but once approved will work.