Due to my project structure, and the desire to use the .mvn/maven.config configuration file to specify my default maven configuration, I have created my build definition as a Freestyle project.
The build runs successfully, however I would like to include the version number in a tag in a post-build step. Unfortunately, the maven POM_VERSION variable(s) are not accessible in a Freestyle project (only in a Maven build project). Is there some other way I can extract the Version value from the pom.xml file?
I found a link in StackOverflow (
https://stackoverflow.com/a/15879521/827480) executing a system groovy script but it was from 2013, and does not seem to export the POM_VERSION value as an environment variable in Jenkins 2.46+. Additionally, from my understanding, this kind of workaround would only execute on a master node, which may be problematic.
import jenkins.util.*;
import jenkins.model.*;
def thr = Thread.currentThread();
def currentBuild = thr?.executable;
def workspace = currentBuild.getModuleRoot().absolutize().toString();
def project = new XmlSlurper().parse(new File("$workspace/pom.xml"))
def param = new hudson.model.StringParameterValue("POM_VERSION", project.version.toString())
currentBuild.addAction(new hudson.model.ParametersAction(param));
Is there another (ie: better) way to extract the version number from the pom file in a freestyle build?
Thanks,
Eric