Eric,

You certainly can run groovy script if you have the EnvInject plugin. 
 Another way to obtain the pom version is to run shell command:

    mvn -N -Dexec.executable="echo" -Dexec.args='${project.version}' 
org.codehaus.mojo:exec-maven-plugin:1.3.1:exec


On Wednesday, July 26, 2017 at 2:24:52 PM UTC-7, Eric B wrote:
>
> 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/b634e3e4-79d6-450b-b115-05af67bdd291%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to