Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accesing release version of maven-release-plugin

I am using maven-release-plugin in my Jenkins job and I have a "Run build step before SCM runs" enabled where I am executing a shell script. I want to access the release version in this shell script but unable to access it. I am not sure what's the variable that stores the release version in this plugin.

I have tried using

\"release_version\": \"$releaseVersion\"

as I saw the maven command being executed was: Executing Maven: -B -f /workspace/myProject/pom.xml -DdevelopmentVersion=0.0.34-SNAPSHOT -DreleaseVersion=0.0.33 -Dtag=v0.0.33 -U -DignoreSnapshots=true -Darguments=-Dpaypal.buildid=${FUSION_BUILD_GENERATED} -DskipTests=false -Dmaven.javadoc.skip=true -Dresume=false release:prepare release:perform

and also

\"release_version\": \"$MVN_RELEASE_VERSION\"

Both of them didn't work.

like image 452
animesh143 Avatar asked Sep 20 '25 05:09

animesh143


1 Answers

The maven-release-plugin derives the releaseVersion from the project.version element in your pom.xml. Also note that -DreleaseVersion=0.0.33 is passing that value as an argument, so there are no variables involved that you can use from outside the plugin.

However, if you need the release version in your script you can use

mvn help:evaluate -Dexpression=project.version -q -DforceStdout

This will give you something like 1.0.1-SNAPSHOT, depending on your version schema. You can get rid of the -SNAPSHOT via bash commands like cut -d- -f1. Or you run something like

mvn release:prepare -DdryRun=true

which gives you a file named pom.xml.tag. This contains the version element without -SNAPSHOT. Use the command above to read it from the XML file. Afterwards you can clean up the directory with mvn release:clean

like image 178
newur Avatar answered Sep 22 '25 05:09

newur