git验证线上的版本是否符合预期
作者:Linyb极客之路 发布时间:2023-03-04 16:24:09
标签:git,验证,线上版本
git-commit-id-maven-plugin插件,会根据当前分支的版本号生成一个git.properties文件。
git.properties内容形如下
git.branch=master
git.build.host=xxx
git.build.time=2022-03-01T20\:33\:43+0800
git.build.user.email=aaa@qq.com
git.build.user.name=aaa
git.build.version=1.0-SNAPSHOT
git.closest.tag.commit.count=
git.closest.tag.name=
git.commit.id=6dab4430864e3e4a9fc1ba6f6b93f278100d4e2e
git.commit.id.abbrev=6dab443
git.commit.id.describe=6dab443-dirty
git.commit.id.describe-short=6dab443-dirty
git.commit.message.full=Add README.md
git.commit.message.short=Add README.md
git.commit.time=2022-03-01T16\:24\:48+0800
git.commit.user.email=aa@example
git.commit.user.name=aa
git.dirty=true
git.remote.origin.url=http://hello
git.tags=
git.total.commit.count=1
如何使用
本文以springboot项目为例,springboot项目的parent pom里面已经内嵌git-commit-id-maven-plugin插件管理依赖。如下
<pluginManagement>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
</configuration>
</plugin>
</plugins>
</pluginManagement>
项目中做如下配置
1、在我们的项目中显式引入git-commit-id-plugin插件
<build>
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
</plugin>
</plugins>
</build>
2、通过和actuator集成,显示git信息
a、在项目中引入actuator GAV
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
b、浏览器访问http://ip : port/actuator/info
如果觉得上面的信息不够多,我们可以通过自定义端点或者自己写一个controller把信息展示出来
详细的信息可以通过org.springframework.boot.info.GitProperties展示
本示例以自定义端点为例。示例如下
@Endpoint(id = "git")
@Component
public class GitEndpoint {
@Autowired(required = false)
private GitProperties gitProperties;
@ReadOperation
public Object info() throws IOException {
if(ObjectUtils.isEmpty(gitProperties)){
return new HashMap<>();
}
return gitProperties;
}
}
在application.yml中开放自定义端点
management:
endpoints:
web:
exposure:
include: 'git'
浏览器访问http://ip : port/actuator/git
如果仍然觉得上述的信息还是不够详细,那可以通过解析git.properties文件显示。示例
@Endpoint(id = "gitDetail")
@Slf4j
@Component
public class GitDetailEndPoint {
@ReadOperation
public Object detail() throws IOException {
Properties props = null;
try {
props = PropertiesLoaderUtils.loadAllProperties("git.properties");
return props;
} catch (IOException e) {
log.error("git.properties not found");
} finally {
}
return new HashMap<>();
}
}
在application.yml中开放自定义端点
management:
endpoints:
web:
exposure:
include: 'gitDetail'
浏览器访问http://ip:port/actuator/gitDetail
来源:http://166z.cn/86tP


猜你喜欢
- 有如下 borg pattern 的实现:class Borg(object): __shared_state = {}def
- 如下所示:# -*- coding: utf-8 -*-import sysfrom PySide.QtGui import *from P
- 本文实例讲述了Go语言生成随机数的方法。分享给大家供大家参考。具体实现方法如下:golang生成随机数可以使用math/rand包packa
- python之参数,定义时小括号中的参数,用来接收参数用的,称为 “形参”调用时小括号中的参数,用来传递给函数用的,称为 “实参”。1、思考
- Flappy Bird是前段时间(好像一年or两年前....)特别火的有一个小游戏,相信大家都玩过。Flappy Bird操作简单,通过点击
- 本文实例讲述了python函数enumerate,operator和Counter使用技巧。分享给大家供大家参考,具体如下:最近看人家的代码
- jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team,包括来自德国的J&
- 题目描述原题链接 :268. 丢失的数字给定一个包含 [0, n] 中 n 个数的数组 nums ,找出 [0
- 先上图片词云图需要模板pip install jiebapip install wordcloud还需要安装另外两个东西这两个我也不太懂借鉴
- 原理请查看前面几篇文章。1、数据源SH600519.csv 是用 tushare 模块下载的 SH600519 贵州茅台的日 k 线数据,本
- 5.0版本和之前版本的差异较大,本篇对熟悉3.2版本的用户给出了一些5.0的主要区别。URL和路由5.0的URL访问不再支持普通URL模式,
- JS代码:function showFlash(src,w,h){ html&nbs
- 前言python爬虫系列文章的第3篇介绍了网络请求库神器 Requests ,请求把数据返回来之后就要提取目标数据,不同的网站返回的内容通常
- 修改MySql Server安装目录下的 my.ini 文件,在mysqld节下加入下面一行set-variable=lower_case_
- 实现一个mysql数据库封装需要考虑的问题1.使用方便性采用直接sql语句操作方式。只要会写sql语句,那么将没有其他学习成本。uctphp
- PDOStatement::debugDumpParamsPDOStatement::debugDumpParams — 打印一条 SQL
- 简介要建立一个允许过滤和分页的列表页,你必须让一些独立的东西一起工作。Django的对象关系映射器(ORM)和内置的分页类使开发者在不了解如
- Math 对象js 给我们提供了一些操作数字的方法也是一种数据类型 是复杂数据类型Math对象的通用语法: Math.xxx()random
- 以用户为中心的设计、用户体验,这两个词现在在互联网上几乎随处可见,除了设计师外,很多的用户也都在说这两个词,于是我们经常会听到诸如“这里用户
- go官方仅提供了database package,database package下有两个包sql,sql/driver。这两个包用来定义操