简体   繁体   English

maven发布插件 - 操纵项目发布版本

[英]maven release plugin - manipulating project release version

I'm trying to configure in Jenkins a maven release build with customized release version that includes the branch from which the release was made. 我正在尝试在Jenkins中配置maven发布版本,其中包含自定义版本,其中包含发布版本的分支。

It looks something like this: 它看起来像这样:

release:prepare -DreleaseVersion=${project.version}-${GIT_LOCAL_BRANCH}-Release release:perform release:prepare -DreleaseVersion = $ {project.version} - $ {GIT_LOCAL_BRANCH} - 释放:执行

everything works fine, except that the 'project.version' placeholder, which calculated based on the pom, contains the '-SNAPSHOT' postfix. 一切正常,除了'project.version'占位符,它基于pom计算,包含'-SNAPSHOT'后缀。

is there other placeholder which I can use to get it without the '-SNAPSHOT' ? 是否有其他占位符,我可以用它来获得它没有'-SNAPSHOT' I know that the maven release plugin, by default, will set the right version - only I want to manipulate that value. 我知道默认情况下,maven发布插件会设置正确的版本 - 只是我想操纵该值。

is there other placeholder which I can use to get it without the '-SNAPSHOT'? 是否有其他占位符,我可以用它来获得它没有'-SNAPSHOT'?

Unfortunately I believe the answer to your question is "no, there is no built-in variable that will satisfy your needs". 不幸的是,我相信你的问题的答案是“不,没有内置的变量可以满足你的需求”。 However, you could try creating a property and then using that property inside of your project's version tag. 但是,您可以尝试创建属性,然后在项目的版本标记内使用该属性。

I am not able to test this as I don't have the appropriate environment set up and it's rather late so I'm not going to have the time to set it up right now. 我无法测试这个,因为我没有适当的环境设置,而且已经很晚了,所以我现在没有时间设置它。 I will outline my idea and perhaps it will help you: 我将概述我的想法,也许它会帮助你:

You could do something like this in your POM: 您可以在POM中执行以下操作:

<version>${artifactReleaseVersion}-SNAPSHOT</version>
<properties>
    <artifactReleaseVersion>0.0.1</artifactReleaseVersion>
</properties>

Then run your goals using that property: 然后使用该属性运行您的目标:

release:prepare -DreleaseVersion=${artifactReleaseVersion}-${GIT_LOCAL_BRANCH}-Release release:perform

See the offical docu https://maven.apache.org/maven-ci-friendly.html . 请参阅官方文档https://maven.apache.org/maven-ci-friendly.html

There are 3 properties maven supports since 3.5: ${revision} , ${sha1} and ${changelist} . 自3.5以来,maven支持3个属性: ${revision}${sha1}${changelist} So you can use something like 所以你可以使用类似的东西

<version>${revision}${changelist}</version>
  ...
<properties>
  <revision>1.3.1</revision>
  <changelist>-SNAPSHOT</changelist>
</properties>

And call it with 并称之为

release:prepare -DreleaseVersion=${revision}-${GIT_LOCAL_BRANCH}-Release

But the maven-release-plugin does not work nicely together with the CI friendly versions. maven-release-plugin与CI友好版本并不能很好地协同工作。 Read: it will probably overwrite your placeholders in the version tag. 阅读:它可能会覆盖版本标记中的占位符。 So in the end you might just manipulate the -SNAPSHOT string via bash commands. 所以最后你可能只是通过bash命令操纵-SNAPSHOT字符串。

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

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