Aarij Siddiqui Aarij Siddiqui - 2 months ago 103
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:

@NonCPS
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

Answer

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).