简体   繁体   English

如何使用Maven和Jenkins从快照过渡到发布

[英]How to go from snapshot to release with maven and jenkins

I am using Maven as my build tool and Jenkins as my build server. 我使用Maven作为构建工具,使用Jenkins作为构建服务器。 I am trying to make it easy to develop and build. 我正在尝试使其易于开发和构建。

I have the following: 我有以下内容:

Global pom 全球pom

<project>
    <!-- ... -->
    <artifactId>global-pom</artifactId>
    <!-- ... -->
</project>

Libraries pom (parent pom is Global), this has a load of common libraries 库pom(父pom为全局库),这具有大量的公共库

<project>
    <!-- ... -->
    <version>2.0-SNAPSHOT</version>
    <artifactId>libraries-pom</artifactId>

    <parent>
        <!-- ... -->
        <artifactId>global-pom</artifactId>
        <version>2.0-SNAPSHOT</version>
    </parent>

    <properties>
        <libraries.version>2.0-SNAPSHOT</libraries.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- ... -->
                <artifactId>library-one</artifactId>
                <version>${libraries.version}</version>
            </dependency>
            <dependency>
                <!-- ... -->
                <artifactId>library-two</artifactId>
                <version>${libraries.version}</version>
            </dependency>
            <!-- ... -->
        </dependencies>
    </dependencyManagement>

    <modules>
        <module>library-one</module>
        <module>library-two</module>
        <!-- ... -->
    </modules>
</project>

A common library (parent pom is Libraries) pom will look like this: 通用库(父pom是库)pom看起来像这样:

<project>
    <!-- ... -->
    <version>2.0-SNAPSHOT</version>
    <artifactId>library-one</artifactId>

    <parent>
        <!-- ... -->
        <artifactId>libraries-pom</artifactId>
        <version>2.0-SNAPSHOT</version>
    </parent>

    <!-- ... -->
</project>

Then a service pom (parent pom is Libraries) that may look like this: 然后一个服务pom(父pom是库)可能看起来像这样:

<project>
    <!-- ... -->
    <version>1.0-SNAPSHOT</version>
    <artifactId>service-one</artifactId>

    <parent>
        <!-- ... -->
        <artifactId>libraries-pom</artifactId>
        <version>2.0-SNAPSHOT</version>
    </parent>

    <!-- ... -->
</project>

Now this is all well and good when I am developing locally. 现在,当我在本地开发时,这一切都很好。 I can have all these poms in my Intellij project and if I change something in one of the libraries to be used in one of the projects, then when I build and run locally, it knows to build the library first, etc... 我可以在Intellij项目中拥有所有这些poms,如果我更改其中一个项目中要使用的库之一,那么当我在本地构建并运行时,它知道首先构建库,依此类推。

Whenever something is checked in, a SNAPSHOT version automatically builds on Jenkins. 只要签入内容,便会在Jenkins上自动构建SNAPSHOT版本。

When I come to actually releasing I don't want to be using SNAPSHOT versions, I want to use "real" versions and I am wondering how best to manage this so as to not impact development or releases. 当我真正发布时,我不想使用SNAPSHOT版本,我想使用“真实”版本,我想知道如何最好地管理它,以免影响开发或发布。

Has anyone got any ideas? 有人知道吗? Ideally, when I want to release, I'd like to goto my build server and click build and it automatically sort everything out for me - is this possible? 理想情况下,当我要发布时,我想转到构建服务器并单击“构建”,它会自动为我整理所有内容-这可能吗?

You will need to use the Maven release plugin to perform automated releases of all your artifacts, by issuing some Maven command-line instructions in batch mode. 您将需要使用Maven发布插件,通过以批处理方式发布一些Maven命令行指令来执行所有工件的自动发布。

For that include the following configuration in your parent pom: 为此,在父pom中包括以下配置:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
      <autoVersionSubmodules>true</autoVersionSubmodules>
      <tagNameFormat>v@{project.version}</tagNameFormat>
      <goals>deploy</goals>
    </configuration>
</plugin>

To make a release, you need to execute two steps. 要发布,您需要执行两个步骤。 First mvn -B release:prepare and mvn -B release:perform . 第一个mvn -B release:preparemvn -B release:perform

By running Maven in batch mode (-B) these steps automatically will make a release, tag, deploy to a remote repository and push the changes to your version control system (assuming git), which must be specified in the pom. 通过以批处理模式(-B)运行Maven,这些步骤将自动进行发行,标记,部署到远程存储库,并将更改推送到您的版本控制系统(假设git),必须在pom中指定。

However, to test if the steps are doing what you intend, I would first run them locally in interactive mode (without -B), and including some extra configuration to the plugin: 但是,要测试这些步骤是否按照您的预期进行,我首先将在交互式模式下(不带-B)在本地运行它们,并对插件进行一些额外的配置:

<localCheckout>true</localCheckout>
<pushChanges>false</pushChanges>

These will prevent a push to git. 这些将阻止推送到git。 If something is not right with the release, you can then do mvn release:rollback and clean up the git repo locally, and then fixing the release plugin configuration. 如果发行版不正确,则可以执行mvn release:rollback并在本地清理git repo,然后修复发行版插件配置。

To run that in Jenkins, you need create a new job that will run both prepare and perform commands in batch mode. 要在Jenkins中运行该程序,您需要创建一个新作业,该作业将以批处理方式运行prepareperform命令。

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

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