How to read and write a pom in Jenkins ?

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 = read…


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

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to read and write a pom in Jenkins ?." Maxime Guilbert | Sciencx - Tuesday August 31, 2021, https://www.scien.cx/2021/08/31/how-to-read-and-write-a-pom-in-jenkins/
HARVARD
Maxime Guilbert | Sciencx Tuesday August 31, 2021 » How to read and write a pom in Jenkins ?., viewed ,<https://www.scien.cx/2021/08/31/how-to-read-and-write-a-pom-in-jenkins/>
VANCOUVER
Maxime Guilbert | Sciencx - » How to read and write a pom in Jenkins ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/31/how-to-read-and-write-a-pom-in-jenkins/
CHICAGO
" » How to read and write a pom in Jenkins ?." Maxime Guilbert | Sciencx - Accessed . https://www.scien.cx/2021/08/31/how-to-read-and-write-a-pom-in-jenkins/
IEEE
" » How to read and write a pom in Jenkins ?." Maxime Guilbert | Sciencx [Online]. Available: https://www.scien.cx/2021/08/31/how-to-read-and-write-a-pom-in-jenkins/. [Accessed: ]
rf:citation
» How to read and write a pom in Jenkins ? | Maxime Guilbert | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.