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

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/1f59886a-149c-4b21-b940-0b2b83b9ba0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to