diff --git a/life-helper-system/src/main/java/com/weutil/system/config/PipelineProperties.java b/life-helper-system/src/main/java/com/weutil/system/config/PipelineProperties.java new file mode 100644 index 0000000..ba86bee --- /dev/null +++ b/life-helper-system/src/main/java/com/weutil/system/config/PipelineProperties.java @@ -0,0 +1,30 @@ +package com.weutil.system.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 流水线信息 + * + *

说明 + *

CI/CD 阶段的流水线环境变量信息。 + * + * @author inlym + * @date 2024/12/11 + * @see 环境变量 + * @since 3.0.0 + **/ +@Component +@ConfigurationProperties(prefix = "pipeline") +@Data +public class PipelineProperties { + /** 流水线的运行编号,从1开始,按自然数自增 */ + private String buildNumber; + + /** 本次部署代码版本的 commit ID */ + private String commitSha; + + /** 本次部署代码版本的分支名或标签名 */ + private String commitRefName; +} diff --git a/life-helper-system/src/main/java/com/weutil/system/controller/SystemController.java b/life-helper-system/src/main/java/com/weutil/system/controller/SystemController.java index a8d44db..b2d5ce4 100644 --- a/life-helper-system/src/main/java/com/weutil/system/controller/SystemController.java +++ b/life-helper-system/src/main/java/com/weutil/system/controller/SystemController.java @@ -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; @@ -36,6 +37,7 @@ public class SystemController { private final Environment environment; private final LaunchTimeService launchTimeService; private final DelayTimeService delayTimeService; + private final PipelineProperties pipelineProperties; /** * 查看系统服务器运行信息 @@ -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) @@ -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` 原因说明