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
135 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,050 points

Related Questions In Jenkins

+2 votes
5 answers
0 votes
2 answers
+4 votes
7 answers

How to set the pipeline name and description for a Jenkinsfile?

You can rename pipeline jobs in jenkins ...READ MORE

answered Oct 11, 2018 in Jenkins by Hannah
• 14,080 points
4,049 views
0 votes
1 answer

How to start Jenkins on a different port rather than 8080?

This is simple, use the following command: java ...READ MORE

answered Jul 4, 2018 in Jenkins by Sophie may
• 9,050 points
795 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,050 points
796 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,050 points
338 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.