简体   繁体   English

正在访问Maven-release-plugin的发行版本

[英]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. 我在Jenkins作业中使用了maven-release-plugin,并且在执行外壳脚本的地方启用了“在SCM运行之前运行构建步骤”。 I want to access the release version in this shell script but unable to access it. 我想在此Shell脚本中访问发行版本,但无法访问它。 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 我看到正在执行的Maven命令是:正在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 . maven-release-plugin从pom.xml中project.version元素派生releaseVersion。 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. 另请注意, -DreleaseVersion=0.0.33将该值作为参数传递,因此不涉及可从插件外部使用的变量。

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. 根据您的版本架构,这将为您提供1.0.1-SNAPSHOT之类的信息。 You can get rid of the -SNAPSHOT via bash commands like cut -d- -f1 . 你可以摆脱-SNAPSHOT的通过庆典命令,如cut -d- -f1 Or you run something like 或者你运行类似

mvn release:prepare -DdryRun=true

which gives you a file named pom.xml.tag . 这将为您提供一个名为pom.xml.tag的文件。 This contains the version element without -SNAPSHOT . 它包含不带-SNAPSHOT的version元素。 Use the command above to read it from the XML file. 使用上面的命令从XML文件读取它。 Afterwards you can clean up the directory with mvn release:clean 之后,您可以使用mvn release:clean目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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