简体   繁体   English

Jenkins 发布 Maven

[英]Maven release from Jenkins

I have the following modules in my project,我的项目中有以下模块,

module - 1
module - 2 
module - 3
module - 4

In the Jenkins maven release, I have to release only the module - 1 and module - 2.在 Jenkins maven 版本中,我只需要发布模块 - 1 和模块 - 2。

For this I have created the profile in root pom which includes the module -1 and module -2.为此,我在 root pom 中创建了配置文件,其中包括模块 -1 和模块 -2。

<profile>
    <id>jenkins-release</id>
    <modules>
        <module>module - 1</module>
        <module>module - 2</module>
    </modules>
</profile>

How can I make this profile to be executed during Jenkins maven release?如何在 Jenkins maven 发布期间执行此配置文件?

specifying the profile ( -P jenkins-release release:prepare release:perform ) under "release goals and options" in Jenkins does not work.在 Jenkins 的“发布目标和选项”下指定配置文件( -P jenkins-release release:prepare release:perform )不起作用。

In local it works with:在本地,它适用于:

mvn -P jenkins-release release:perform

在此处输入图片说明

Your local invocation is not the same.您的本地调用不一样。 You only specified the goal release:prepare whereas in Jenkins it's release:prepare release:perform .您只指定了目标release:prepare而在 Jenkins 中它是release:prepare release:perform

There are multiple invocations taking place, and therefore you need to use有多个调用发生,因此您需要使用

-Darguments=-Pjenkins-release

You'll notice that I omitted the space between -P and jenkins-release in order to avoid putting the whole thing between quotes, but I'll leave that to you.你会注意到我省略了-Pjenkins-release之间的空格,以避免将整个内容放在引号之间,但我会把它留给你。

Another option would be to use the releaseProfile setting for the release plugin.另一种选择是使用发布插件的releaseProfile设置。

Please see Profile activation on both release:prepare and release:perform for more details.有关更多详细信息,请参阅release:prepare 和 release:perform 上的配置文件激活

It's a bit verbose but you should be activating the profile both with -P (for release:prepare ) and with -Darguments=... (for release:perform ).这有点冗长,但您应该使用-P (用于release:prepare )和-Darguments=... (用于release:perform )激活配置文件。 Also, make sure you use the latest version of maven-release-plugin , as this was buggy a while back.另外,请确保您使用最新版本的maven-release-plugin ,因为这在一段时间内有问题。

Like this: mvn -Darguments=-Pjenkins-release -Pjenkins-release release:prepare release:perform像这样: mvn -Darguments=-Pjenkins-release -Pjenkins-release release:prepare release:perform

Another approach is to have the profile activate on a custom system property (eg -DdoMyRelease=true ) or an environment variable that you set through Jenkins.另一种方法是在自定义系统属性(例如-DdoMyRelease=true )或您通过 Jenkins 设置的环境变量上激活配置文件。

Have you explored the <releaseProfiles> option?您是否探索过<releaseProfiles>选项? Put it in the root POM if it is from there you are doing your releases.如果它是从那里发布的,请将其放在根 POM 中。

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

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