git驗(yàn)證線上的版本是否符合預(yù)期
正文
git-commit-id-maven-plugin插件,會(huì)根據(jù)當(dāng)前分支的版本號(hào)生成一個(gè)git.properties文件。
git.properties內(nèi)容形如下
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項(xiàng)目為例,springboot項(xiàng)目的parent pom里面已經(jīng)內(nèi)嵌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>項(xiàng)目中做如下配置
1、在我們的項(xiàng)目中顯式引入git-commit-id-plugin插件
<build> ????????<plugins> ????????????<plugin> ????????????????<groupId>pl.project13.maven</groupId> ????????????????<artifactId>git-commit-id-plugin</artifactId> ????????????</plugin> ????????</plugins> ?</build>
2、通過(guò)和actuator集成,顯示git信息
a、在項(xiàng)目中引入actuator GAV
<dependency> ????????????<groupId>org.springframework.boot</groupId> ????????????<artifactId>spring-boot-starter-actuator</artifactId> ????????</dependency>
b、瀏覽器訪問(wèn)http://ip : port/actuator/info

如果覺得上面的信息不夠多,我們可以通過(guò)自定義端點(diǎn)或者自己寫一個(gè)controller把信息展示出來(lái)
詳細(xì)的信息可以通過(guò)org.springframework.boot.info.GitProperties展示
本示例以自定義端點(diǎn)為例。示例如下
@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中開放自定義端點(diǎn)
management: ??endpoints: ????web: ??????exposure: ????????include:?'git'
瀏覽器訪問(wèn)http://ip : port/actuator/git

如果仍然覺得上述的信息還是不夠詳細(xì),那可以通過(guò)解析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中開放自定義端點(diǎn)
management: ??endpoints: ????web: ??????exposure: ????????include:?'gitDetail'
瀏覽器訪問(wèn)http://ip:port/actuator/gitDetail

總結(jié)
git-commit-id-maven-plugin在分布式或者微服務(wù)項(xiàng)目中,用來(lái)驗(yàn)證項(xiàng)目版本還是挺有用的,推薦大家有機(jī)會(huì)用一下
以上就是git驗(yàn)證線上的版本是否符合預(yù)期的詳細(xì)內(nèi)容,更多關(guān)于git驗(yàn)證線上版本的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
各類常見語(yǔ)言清除網(wǎng)頁(yè)緩存方法匯總
這篇文章主要介紹了各類常見語(yǔ)言清除網(wǎng)頁(yè)緩存方法匯總,包括了常見的html、asp、php與java,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-10-10
Unity開發(fā)VR項(xiàng)目問(wèn)題總結(jié)分析
本篇文章主要對(duì)Unity開發(fā)VR項(xiàng)目會(huì)遇到的一些問(wèn)題總結(jié),針對(duì)這些問(wèn)題進(jìn)行分析解決,有需要的朋友可以借鑒參考下,希望對(duì)大家有所幫助2021-09-09
自定義?Github?Action?庫(kù)實(shí)戰(zhàn)詳解
這篇文章主要為大家介紹了自定義?Github?Action?庫(kù)實(shí)戰(zhàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
文章中優(yōu)酷視頻全屏及去除廣告在線轉(zhuǎn)換
很多網(wǎng)站發(fā)表了引用優(yōu)酷視頻不能全屏,或一點(diǎn)全屏又跳到官方網(wǎng)了,結(jié)果又要重新緩沖。用戶體驗(yàn)特別不好。2010-09-09

