This content originally appeared on DEV Community and was authored by Maxime Guilbert
When I started to work with Jenkins with Java apps, I quickly have these questions
How to be able to read a pom?
How to update it?
Am I able to update the pom version from Jenkins??
So today, we will see how to do it!
Read
pom = readMavenPom(file: 'pom.xml')
def pom_version = pom.version
The reading part looks like all the other read functions in Jenkins (like readYaml, readJSON...)
Links
- Jenkins documentation : https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readmavenpom-read-a-maven-project-file
Write
def pom = readMavenPom file: 'pom.xml'
//Do some manipulation
pom.version = "x.x.x"
...
writeMavenPom model: pom
The write part is really simple and you just have to give back the pom object you retrieve from reading;
Links
- Jenkins documentation : https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#writemavenpom-write-a-maven-project-file
Bonus - Update pom version
Once we know that, we can automatically change the version in the pom!
def pom = readMavenPom file: 'pom.xml'
pom_version_array = pom.version.split('\\.')
// You can choose any part of the version you want to update
pom_version_array[1] = "${pom_version_array[1]}".toInteger() + 1
pom.version = pom_version_array.join('.')
writeMavenPom model: pom
I hope it will help you!
This content originally appeared on DEV Community and was authored by Maxime Guilbert
Maxime Guilbert | Sciencx (2021-08-31T15:20:03+00:00) How to read and write a pom in Jenkins ?. Retrieved from https://www.scien.cx/2021/08/31/how-to-read-and-write-a-pom-in-jenkins/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.