【问题标题】:How to generate application version using Spring Boot, Gradle, Semantic Versioning and Jenkins如何使用 Spring Boot、Gradle、Semantic Versioning 和 Jenkins 生成应用程序版本
【发布时间】:2017-01-11 01:53:40
【问题描述】:

我有一个启用了执行器的 Spring Boot Web 应用程序。当我打开<app_url>/info 时,我看到如下

{
    "git": {
        "commit": {
            "time": "2016-08-31T17:53:28.000+0000",
            "id": "0a52a2f"
        },
        "branch": "master"
    },
    "build": {
        "version": "unspecified",
        "artifact": "my-app",
        "name": "my-app",
        "group": "",
        "time": "2016-09-02T21:09:42.000+0000"
    }
}

我不确定如何在此处生成版本号。我想使用语义版本控制MAJOR.MINOR.PATCH+timestamp+Build_Number

关于存储包的构建信息的普遍共识是什么?我不想将它存储在application.yml 中,因为它由 Puppet 管理并且在应用程序战争之外。我希望它由 Jenkins 生成到某个文件中,Spring Boot 可以从该文件中获取它。我应该让 Jenkins 写入由 spring-boot-gradle-plugin buildInfo 生成的 build-info.properties 吗?还是应该在生成文件时由 Gradle 自己生成版本? Gradle 是如何知道MAJOR.MINOR.PATCH 的详细信息的?我已经没有关于如何将所有这些整合在一起的想法了。

【问题讨论】:

    标签: gradle spring-boot semantic-versioning spring-boot-actuator spring-boot-gradle-plugin


    【解决方案1】:

    有点晚了,但这就是我的做法(似乎有效)。

    springBoot  {
        buildInfo {
            additionalProperties = [
                "version" : System.properties["version"] != null ? System.properties["version"] : "unspecified"
            ]
        }
    }
    

    然后在我的 Jenkins 流水线中

    ./gradlew clean build -Dversion=${MAJOR}.${MINOR}.${PATCH}
    

    然后输出 jar 将有一个 build-info.properties

    build.version=1.0.1
    

    【讨论】:

      猜你喜欢
      • 2020-11-10
      • 2019-11-26
      • 2020-04-13
      • 2015-04-14
      • 2021-02-19
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多