<?xml version="1.0" encoding="utf-8" standalone="no"?>
<test-run id="2" testcasecount="596" result="Failed" total="596" passed="448" failed="148" inconclusive="0" skipped="0" asserts="812" engine-version="3.6.0.0" clr-version="4.0.30319.42000" start-time="2017-01-30 07:19:45Z" end-time="2017-01-30 07:31:25Z" duration="700.676581">
I have to read the result attribute from above xml from jenkins file I could fetch the result from groovy script but unable to fetch from Jenkin script file
How to access xml attributes from JenkinsFile?
i am facing the below issue
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new groovy.util.XmlSlurper
Assuming accessing this from groovy is ok, the following works:
def str = '''\
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<test-run id="2" testcasecount="596" result="Failed" total="596" passed="448" failed="148" inconclusive="0" skipped="0" asserts="812" engine-version="3.6.0.0" clr-version="4.0.30319.42000" start-time="2017-01-30 07:19:45Z" end-time="2017-01-30 07:31:25Z" duration="700.676581">
</test-run>
'''
def xml = new XmlParser().parseText(str)
println "Test result: ${xml.@result}"
Note that I added an end tag for the test-result element. The at character @ is used to access attribute values.
The above prints:
Test result: Failed
Edit: After re-reading I realize you are looking for a non groovy solution. I will leave this here in case a groovy fallback would be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With