Hi,
How do I parse xml file in a pipeline job?
This is what I tried: I have an XML file I want to parse, looking like this:
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="origin" fetch="XXX" review="YYYY" />
<default remote="origin" />
<project path="home/projectA" name="projectA" revision="master" groups="A"/>
<project path="home/projectB" name="projectB" revision="master" groups="A"/>
<project path="some_folder/projectC" name="projectC" revision="master" groups="B"/>
<project path="some_folder/projectD" name="projectD" revision="master" groups="C"/>
</manifest>
I want to parse this file in order to get the groups element values.
My code:
git branch: "master", credentialsId: "<>", url: "<manifest repository>"
def xml = readFile(encoding: 'UTF-8', file: "manifest.xml")
def parsed_manifest = new XmlParser().parseText(xml)
clusters = []
parsed_manifest.project.each {
values = it.attribute("groups").split(',')
for (item in values) {
if (item.startsWith("cluster")) {
clusters.add(item)
}
}
}
I run it as a Jenkins file that is being loaded from my git repository and not as a script written in the job's configuration (running the script when written in the job configuration, passes successfully.)
The error I get:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified field groovy.util.Node project
(https://issues.jenkins-ci.org/browse/JENKINS-37398 - a similar error)
Please help :)