Saturday, 21 September 2019

Spring Boot Actuator: Add git commit details to info endpoint


You can add details like git commit time, commit id, branch to the info endpoint using ‘git-commit-id-plugin’.

      <plugin>
        <groupId>pl.project13.maven</groupId>
        <artifactId>git-commit-id-plugin</artifactId>
      </plugin>

Just add above plugin to your pom.xml, info endpoint will pick the information from git.properties file (this file is generated once you perform mvn clean install).

Step 1: Clone the repository 'https://github.com/harikrishna553/gitCommitIdPluginDemo.git'
$git clone https://github.com/harikrishna553/gitCommitIdPluginDemo.git
Cloning into 'gitCommitIdPluginDemo'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 17 (delta 1), reused 17 (delta 1), pack-reused 0
Unpacking objects: 100% (17/17), done.
$
$ls gitCommitIdPluginDemo/
pom.xml src

Step 2: Build the project.


Navigate to gitCommitIdPluginDemo directory and execute the command ‘mvn clean install’.
$cd gitCommitIdPluginDemo/
$
$mvn clean install


Once you build the project, it generate 'git.properties' file under target/classes folder.
$ls target/
actuatorDemo-1.jar    classes       maven-archiver
actuatorDemo-1.jar.original generated-sources   maven-status
$
$ls target/classes/
META-INF    application.properties  com     git.properties

Step 4: Run actuatorDemo-1.jar  file
java -jar ./target/actuatorDemo-1.jar


Open the url 'http://localhost:8080/actuator/info' in browser, you will get below response.
{
  "team": {
    "name": "Alaska",
    "size": "23",
    "dev": "krishna, ram, Sunil, Bikash",
    "test": "hari, pani, panth"
  },
  "version": "1.23",
  "product": {
    "owner": "Ashwani",
    "architect": "Surav"
  },
  "git": {
    "commit": {
      "time": "2019-09-05T06:17:06Z",
      "id": "f0df5e0"
    },
    "branch": "master"
  },
  "build": {
    "version": "1",
    "artifact": "actuatorDemo",
    "name": "actuatorDemo",
    "group": "actuatorDemo",
    "time": "2019-09-05T06:23:59.802Z"
  }
}



Previous                                                    Next                                                    Home

No comments:

Post a Comment