How to get the Maven Version of a project in Jenkins?

0 votes

Can the Jenkins build be aware of the Maven version number of a project after processing the POM?

Aug 9, 2018 in Jenkins by Tyrion anex
• 8,280 points
383 views

1 answer to this question.

0 votes

Follow the below steps:

1.      Install the Groovy plugin

2.      Add a Post Step to your Maven build of type Execute **system** Groovy script

3.      Paste in the following snippet of Groovy:

Script:

import hudson.model.*;
import hudson.util.*;
def thr = Thread.currentThread();
def currentBuild = thr?.executable;
def mavenVer = currentBuild.getParent().getModules().toArray()[0].getVersion();
def newParamAction = new hudson.model.ParametersAction(new hudson.model.StringParameterValue("MAVEN_VERSION", mavenVer));
currentBuild.addAction(newParamAction);

The build environment variable called MAVEN_VERSION will now be available for substitution into other post-build steps in the usual manner (${MAVEN_VERSION}).

answered Aug 9, 2018 by Sophie may
• 9,430 points

Related Questions In Jenkins

+2 votes
5 answers
0 votes
2 answers
0 votes
1 answer

How to auto build a job in jenkins if there is any change in code on Github repository?

Yes this is possible. Follow these steps. 1. ...READ MORE

answered Jun 20 in Jenkins by Arvind
• 1,650 points
57 views
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer

How to trigger a Jenkins pipeline A in another Jenkins pipeline B?

You can run the following code, its ...READ MORE

answered Jul 5, 2018 in Jenkins by Sophie may
• 9,430 points
2,278 views
0 votes
1 answer

How to construct Maven installation in Jenkins for each Slave node?

I’m assuming that Java and Maven are ...READ MORE

answered Aug 1, 2018 in Jenkins by Sophie may
• 9,430 points
515 views