Given the need to retrieve the version from the POM in a scripted Jenkins pipeline:
node() {
stage('Stage') {
def version = (readFile('pom.xml') =~ '<version>(.+?)</version>')[1][1]
// set build description
currentBuild.description = "${BRANCH_NAME}, ${version}"
}
}
Note: use [1][1]
if you have a parent POM, otherwise [0][1]
.