TechCrunch
TechCrunch

Reputation: 3124

How to generate application version using Spring Boot, Gradle, Semantic Versioning and Jenkins

I have a Spring Boot web application with actuator enabled. When I open <app_url>/info, I see below

{
    "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"
    }
}

I'm not sure how to generate a version number here. I want to use Semantic Versioning MAJOR.MINOR.PATCH+timestamp+Build_Number

What is the general consensus w.r.t storing build information of a package ? I don't want to store it in application.yml because it is managed by Puppet and is external to the application war. I would like it to be generated by Jenkins into some file and Spring Boot can pick it up from that file. Should I let Jenkins write into build-info.properties that is generated by spring-boot-gradle-plugin buildInfo ? or should the version be generated by Gradle itself when it generates the file? How does Gradle know MAJOR.MINOR.PATCH details ? I'm running out of ideas on how to integrate all these together.

Upvotes: 4

Views: 2991

Answers (1)

Danny
Danny

Reputation: 7518

A little late, but this is how I am doing it (seems to work).

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

and then in my Jenkins Pipeline

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

The output jar then will have a build-info.properties

build.version=1.0.1

Upvotes: 1

Related Questions