buildnumber-maven-plugin 构建生成时间戳和当前构建branch

为了方便快捷的了解代码是什么时候构建的,当前运行的代码是从哪个分支构建的,构建时最新的commit id是哪个?

对于上面的问题,可以使用buildnumber-maven-plugin工具自动完成,并将信息反映到页面上。只要打开页面便可以轻松查看。

使用方法:

1. pom.xml文件中配置

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>
<plugins>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>buildnumber-maven-plugin</artifactId>
        <version>1.4</version>
        <executions>
            <execution>
                <id>generate-timestamp</id>
                <phase>validate</phase>
                <goals>
                    <goal>create-timestamp</goal>
                </goals>
                <configuration>
                   <timestampFormat>MMddHHmmss</timestampFormat>
                    <timestampPropertyName>buildTime</timestampPropertyName>
                </configuration>
            </execution>
            <execution>
                <id>generate-buildNumber</id>
                <phase>validate</phase>
                <goals>
                    <goal>create</goal>
                </goals>
                <configuration>
                    <!-- 如果git仓库地址为 http/https
                    <scmConnectionUrl>scm:git:https://github.com/xx/ms.git</scmConnectionUrl>
                    <username>xx@gmail.com</username>
                    <password>xx</password>
                    -->
                    <scmConnectionUrl>scm:git:git@gitlab.lab.com/ms.git</scmConnectionUrl>
                    <shortRevisionLength>8</shortRevisionLength>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

 

2. resource.properties

buildTime=${buildTime}
buildNumber=${buildNumber}
buildBranch=${scmBranch}

3.结果

timestamp=20181025155048
buildNumber=fb847981
scmBranch=develop_20180925

注意:goals create-timestamp和create可以同时配置,但是时间戳格式化需要需要重新指定timestampPropertyName

posted @ 2018-10-25 16:12  A_1023  阅读(4247)  评论(0编辑  收藏  举报