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
You have to mention the path of your application's pom. xml in relation to jenkins work space. Once Jenkins build starts it will download the source code to . jenkins\jobs\yourjobname\workspace and builds it there, you can check this location if you are not sure of the pom path.
You need to put in Jenkins the path to your Eclipse pom. xml. ./Users/enislavmollov/Documents/Maven workspace/MavenProkect/pom. xml or . \Users\enislavmollov\Documents\Maven workspace\MavenProkect\pom.
The @NonCPS annotation is useful when you have methods which use objects which aren't serializable. Normally, all objects that you create in your pipeline script must be serializable (the reason for this is that Jenkins must be able to serialize the state of the script so that it can be paused and stored on disk).
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
).
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