Skip to content

Commit

Permalink
ci: optimize system debug info details
Browse files Browse the repository at this point in the history
  • Loading branch information
inlym committed Dec 10, 2024
1 parent 8013f2c commit 898c915
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.weutil.system.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* 流水线信息
*
* <h2>说明
* <p>CI/CD 阶段的流水线环境变量信息。
*
* @author <a href="https://www.inlym.com">inlym</a>
* @date 2024/12/11
* @see <a href="https://help.aliyun.com/zh/yunxiao/user-guide/environment-variables">环境变量</a>
* @since 3.0.0
**/
@Component
@ConfigurationProperties(prefix = "pipeline")
@Data
public class PipelineProperties {
/** 流水线的运行编号,从1开始,按自然数自增 */
private String buildNumber;

/** 本次部署代码版本的 commit ID */
private String commitSha;

/** 本次部署代码版本的分支名或标签名 */
private String commitRefName;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.weutil.system.controller;

import com.weutil.system.config.PipelineProperties;
import com.weutil.system.model.ServerInfo;
import com.weutil.system.service.DelayTimeService;
import com.weutil.system.service.LaunchTimeService;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class SystemController {
private final Environment environment;
private final LaunchTimeService launchTimeService;
private final DelayTimeService delayTimeService;
private final PipelineProperties pipelineProperties;

/**
* 查看系统服务器运行信息
Expand All @@ -55,11 +57,6 @@ public ServerInfo getServerInfo() {
delay.put("mysql", delayTimeService.calcMysqlDelayTime());
delay.put("redis", delayTimeService.calcRedisDelayTime());

// CI 部署相关参数
String commitId = System.getenv("CI_COMMIT_SHA");
String commitRefName = System.getenv("CI_COMMIT_REF_NAME");
String buildNumber = System.getenv("BUILD_NUMBER");

ServerInfo info = ServerInfo.builder()
.now(now)
.launchTime(launchTime)
Expand All @@ -69,9 +66,9 @@ public ServerInfo getServerInfo() {
.springBootVersion(SpringBootVersion.getVersion())
.timeZone(ZoneId.systemDefault().getId())
.delay(delay)
.commitId(commitId)
.commitRefName(commitRefName)
.buildNumber(buildNumber)
.commitId(pipelineProperties.getCommitSha())
.commitRefName(pipelineProperties.getCommitRefName())
.buildNumber(pipelineProperties.getBuildNumber())
.build();

// 此处使用 `try...catch` 原因说明
Expand Down

0 comments on commit 898c915

Please sign in to comment.