简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM