Aarij Siddiqui Aarij Siddiqui - 9 months ago 278
Groovy Question

Parsing pom.xml file within a Jenkins pipeline (Groovy)

I am trying to parse my pom.xml in jenkins pipeline plugin. I intend to modify it and save it back.

My problem is that it gives me "unclassified field java.lang.String version"

My code is as follows:

groovy.util.Node getPom(path) {
new XmlParser().parseText(readFile(path)).version
node {
groovy.util.Node pomNode = getPom("pom.xml")
println pomNode

Similar issue has been discussed here: Parsing an XML file within a Jenkins pipeline


Why not use (you need pipeline utility steps plugin for this):

pom = readMavenPom file: 'pom.xml'

Now you have access to all data in the pom (as a Model).