I get an error when trying to iterate a xml file in jenkins pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

I get an error when trying to iterate a xml file in jenkins pipeline

jesus fernandez
I am trying to understand how to iterate a .xml file in Jenkins so I create a super simple .xml file:
```
<?xml version="1.0" encoding="utf-8"?>
<tag1>
  <tag2>hello</tag2>
  <tag3>bye</tag3>
</tag1>
  
```
I just want to get acces to a tag value (i.e. tag3) and print it out. I have been reading a lot here on SO and I this is the cod I have:
```
import groovy.xml.*

pipeline {
    agent any

    stages {
        stage('find') {
            steps {
                script{
                    def xml = readFile "C:\\Users\\anton\\Desktop\\test.xml"
                    def file = new XmlSlurper().parseTest(xml)
                    
                    file.'**'.
                        findAll { it.name() == 'tag1' }
                        .each {println it.assetId.text()}
                }
            }
             
        }
    }
}
```

But I keep getting this error: ```hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: groovy.util.XmlSlurper.parseTest() is applicable for argument types: (java.lang.String) values: [<?xml version="1.0" encoding="utf-8"?>``` 
If I try to use XmlParser() method I get the same error too. I have followe these links [java.net.MalformedURLException: no protocol: XML][1] and it seems to work fine for him I do not find further information from that error


  [1]: https://stackoverflow.com/questions/23027382/java-net-malformedurlexception-no-protocol-xml

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bd695356-0707-42fd-8252-8ab4c5f7ab28n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: [EXTERNAL] - I get an error when trying to iterate a xml file in jenkins pipeline

Dirk Heinrichs-3
Am Dienstag, den 17.11.2020, 03:42 -0800 schrieb jesus fernandez:

parseTest(xml)

That should be parseText(), I guess.

HTH...

Dirk
-- 
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText ™ Discovery | Recommind
Phone: +49 2226 15966 18
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, Christian Waida, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3b61b9638164ebfea86616290d91330d7eefa6b9.camel%40opentext.com.

signature.asc (235 bytes) Download Attachment