增加构建通知

This commit is contained in:
dengqichen 2025-11-14 15:01:09 +08:00
parent 46f23104f9
commit d8e65d8855
3 changed files with 36 additions and 27 deletions

View File

@ -1,6 +1,7 @@
package com.qqchen.deploy.backend.framework.exception;
import com.qqchen.deploy.backend.framework.enums.ResponseCode;
import com.qqchen.deploy.backend.framework.utils.MessageUtils;
import lombok.Getter;
@Getter
@ -19,8 +20,18 @@ public abstract class BaseException extends RuntimeException {
}
protected BaseException(ResponseCode errorCode, Object[] args, Throwable cause) {
super(cause);
super(buildMessage(errorCode, args), cause);
this.errorCode = errorCode;
this.args = args;
}
private static String buildMessage(ResponseCode errorCode, Object[] args) {
if (errorCode == null) {
return null;
}
if (args == null || args.length == 0) {
return MessageUtils.getMessage(errorCode.getMessageKey());
}
return MessageUtils.getMessage(errorCode.getMessageKey(), args);
}
}

View File

@ -58,12 +58,13 @@ public abstract class BaseNodeDelegate<I, O> implements JavaDelegate {
// 当前执行上下文用于日志记录
private String currentProcessInstanceId;
private String currentNodeId;
// 预初始化的输出对象子类可以直接访问和修改
// 预初始化的输出对象子类可以直接访问和修改
protected O output;
// 当前输入映射对象用于读取 continueOnFailure 等配置
// 当前输入映射对象用于读取 continueOnFailure 等配置
protected I currentInputMapping;
@Override
@ -106,18 +107,17 @@ public abstract class BaseNodeDelegate<I, O> implements JavaDelegate {
boolean continueOnFailure = WorkflowUtils.getContinueOnFailure(currentInputMapping);
if (continueOnFailure) {
// 非阻断模式标记失败但流程继续
log.warn("⚠️ Node failed (continue mode enabled by config): {}", e.getMessage());
// 非阻断模式标记失败但流程继续
log.error("Node failed (continue mode enabled by config): {}", e.getMessage());
markFailure(e);
// 保存失败状态的 NodeContext
nodeContext.setConfigs(configsMap);
nodeContext.setInputMapping(inputMappingObj);
nodeContext.setOutputs(this.output);
execution.setVariable(currentNodeId, nodeContext.toMap(objectMapper));
} else {
// 阻断模式终止流程默认行为
log.error("Node failed (terminate mode, default): {}", e.getMessage());
//阻断模式终止流程默认行为
log.error("Node failed (terminate mode, default): {}", e.getMessage());
terminateWorkflow(e); // 抛出 BpmnError触发流程终止
}
}
@ -337,7 +337,6 @@ public abstract class BaseNodeDelegate<I, O> implements JavaDelegate {
}
/**
* 创建失败状态的输出对象非致命错误流程继续
* <p>

View File

@ -94,7 +94,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
log.info("Build details - changeSets: {}, artifacts: {}", buildDetails.getChangeSets(), buildDetails.getArtifacts());
// 6. 设置输出结果执行到这里说明构建成功
// 直接修改预初始化的 output 对象
// 直接修改预初始化的 output 对象
// 设置 Jenkins 特有字段
output.setBuildStatus(buildStatus.name());
@ -169,7 +169,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
// 等待一定时间后再检查
Thread.sleep(BUILD_POLL_INTERVAL * 1000L);
// 1. 增量拉取并保存 Jenkins 构建日志
// 1. 增量拉取并保存 Jenkins 构建日志
try {
JenkinsConsoleOutputResponse consoleOutput = jenkinsServiceIntegration.getConsoleOutput(externalSystem, jobName, buildNumber, logOffset);
@ -192,17 +192,17 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
switch (status) {
case SUCCESS:
// 构建成功拉取剩余日志后返回状态
// 构建成功拉取剩余日志后返回状态
log.info("Jenkins build succeeded: job={}, buildNumber={}", jobName, buildNumber);
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
logInfo(String.format("✅ Jenkins 构建成功: buildNumber=%d", buildNumber));
return status;
case FAILURE:
// 构建失败拉取剩余日志后抛出异常
// 构建失败拉取剩余日志后抛出异常
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
throw new RuntimeException(String.format("Jenkins build failed: job=%s, buildNumber=%d", jobName, buildNumber));
case ABORTED:
// 构建被取消拉取剩余日志后抛出异常
// 构建被取消拉取剩余日志后抛出异常
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
throw new RuntimeException(String.format("Jenkins build was aborted: job=%s, buildNumber=%d", jobName, buildNumber));
case IN_PROGRESS:
@ -210,7 +210,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
attempts++;
break;
case NOT_FOUND:
// 构建记录丢失抛出异常
// 构建记录丢失抛出异常
throw new RuntimeException(String.format("Jenkins build not found: job=%s, buildNumber=%d", jobName, buildNumber));
}
} catch (InterruptedException e) {
@ -218,8 +218,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
throw new RuntimeException("Build status polling was interrupted", e);
}
}
throw new RuntimeException(String.format("Jenkins build timed out after %d minutes: job=%s, buildNumber=%d",
MAX_BUILD_POLLS * BUILD_POLL_INTERVAL / 60, jobName, buildNumber));
throw new RuntimeException(String.format("Jenkins build timed out after %d minutes: job=%s, buildNumber=%d", MAX_BUILD_POLLS * BUILD_POLL_INTERVAL / 60, jobName, buildNumber));
}
/**