3

I'm trying to parse XML in Jenkins pipeline using XmlSlurper.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
    <testsuite>
        <properties>
            <property name="outcome" value="Failed"/>
            ...
            <property name="orgWideCoverage" value="73%"/>
        </properties>
        ...

I've tried using direct and map notation and both returns same results.

def testsuites = new XmlSlurper().parseText(testResult)
def properties = testsuites.'**'.find { node ->
    node.name() == 'properties'
}

String outcome = properties.'*'.find { node -> 
    node.name() == 'property' && node['@name'] == 'outcome'
}['@value']
printf("Outcome: %s ", outcome)
String orgWideCoverage = properties.'*'.find { node -> 
    node.name() == 'property' && node['@name'] == 'orgWideCoverage'
}['@value']
printf("Coverage: %s ", orgWideCoverage)

I expect the first case returned value to be Failure and get true instead.

For the second case should be 73% and is false

Piotr Rasała
  • 31
  • 1
  • 3
  • Unfortunately [`XmlSlurper` cannot be used reliably in Jenkins](https://issues.jenkins-ci.org/browse/JENKINS-33024). You should either write a tool to process the XML or, if it's feasible, replace the XML output with JSON/YAML and use the [`readJSON`](https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readjson-read-json-from-files-in-the-workspace)/[`readYaml`](https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readyaml-read-yaml-from-files-in-the-workspace-or-text) steps. – towel Jun 06 '19 at 12:11
  • 1
    @towel For now I made workaround using depthFirst instead of children. I'll get back to it at some time and refactor this. – Piotr Rasała Jun 10 '19 at 19:33

0 Answers0