增加构建通知
This commit is contained in:
parent
46f23104f9
commit
d8e65d8855
@ -1,6 +1,7 @@
|
|||||||
package com.qqchen.deploy.backend.framework.exception;
|
package com.qqchen.deploy.backend.framework.exception;
|
||||||
|
|
||||||
import com.qqchen.deploy.backend.framework.enums.ResponseCode;
|
import com.qqchen.deploy.backend.framework.enums.ResponseCode;
|
||||||
|
import com.qqchen.deploy.backend.framework.utils.MessageUtils;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -19,8 +20,18 @@ public abstract class BaseException extends RuntimeException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected BaseException(ResponseCode errorCode, Object[] args, Throwable cause) {
|
protected BaseException(ResponseCode errorCode, Object[] args, Throwable cause) {
|
||||||
super(cause);
|
super(buildMessage(errorCode, args), cause);
|
||||||
this.errorCode = errorCode;
|
this.errorCode = errorCode;
|
||||||
this.args = args;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -58,12 +58,13 @@ public abstract class BaseNodeDelegate<I, O> implements JavaDelegate {
|
|||||||
|
|
||||||
// 当前执行上下文(用于日志记录)
|
// 当前执行上下文(用于日志记录)
|
||||||
private String currentProcessInstanceId;
|
private String currentProcessInstanceId;
|
||||||
|
|
||||||
private String currentNodeId;
|
private String currentNodeId;
|
||||||
|
|
||||||
// ✅ 预初始化的输出对象(子类可以直接访问和修改)
|
// 预初始化的输出对象(子类可以直接访问和修改)
|
||||||
protected O output;
|
protected O output;
|
||||||
|
|
||||||
// ✅ 当前输入映射对象(用于读取 continueOnFailure 等配置)
|
// 当前输入映射对象(用于读取 continueOnFailure 等配置)
|
||||||
protected I currentInputMapping;
|
protected I currentInputMapping;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -106,18 +107,17 @@ public abstract class BaseNodeDelegate<I, O> implements JavaDelegate {
|
|||||||
|
|
||||||
boolean continueOnFailure = WorkflowUtils.getContinueOnFailure(currentInputMapping);
|
boolean continueOnFailure = WorkflowUtils.getContinueOnFailure(currentInputMapping);
|
||||||
if (continueOnFailure) {
|
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);
|
markFailure(e);
|
||||||
|
|
||||||
// 保存失败状态的 NodeContext
|
// 保存失败状态的 NodeContext
|
||||||
nodeContext.setConfigs(configsMap);
|
nodeContext.setConfigs(configsMap);
|
||||||
nodeContext.setInputMapping(inputMappingObj);
|
nodeContext.setInputMapping(inputMappingObj);
|
||||||
nodeContext.setOutputs(this.output);
|
nodeContext.setOutputs(this.output);
|
||||||
execution.setVariable(currentNodeId, nodeContext.toMap(objectMapper));
|
execution.setVariable(currentNodeId, nodeContext.toMap(objectMapper));
|
||||||
} else {
|
} else {
|
||||||
// ❌ 阻断模式:终止流程(默认行为)
|
//阻断模式:终止流程(默认行为)
|
||||||
log.error("❌ Node failed (terminate mode, default): {}", e.getMessage());
|
log.error("Node failed (terminate mode, default): {}", e.getMessage());
|
||||||
terminateWorkflow(e); // 抛出 BpmnError,触发流程终止
|
terminateWorkflow(e); // 抛出 BpmnError,触发流程终止
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -337,7 +337,6 @@ public abstract class BaseNodeDelegate<I, O> implements JavaDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建失败状态的输出对象(非致命错误,流程继续)
|
* 创建失败状态的输出对象(非致命错误,流程继续)
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@ -94,7 +94,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
|||||||
log.info("Build details - changeSets: {}, artifacts: {}", buildDetails.getChangeSets(), buildDetails.getArtifacts());
|
log.info("Build details - changeSets: {}, artifacts: {}", buildDetails.getChangeSets(), buildDetails.getArtifacts());
|
||||||
|
|
||||||
// 6. 设置输出结果(执行到这里说明构建成功)
|
// 6. 设置输出结果(执行到这里说明构建成功)
|
||||||
// ✅ 直接修改预初始化的 output 对象
|
// 直接修改预初始化的 output 对象
|
||||||
|
|
||||||
// 设置 Jenkins 特有字段
|
// 设置 Jenkins 特有字段
|
||||||
output.setBuildStatus(buildStatus.name());
|
output.setBuildStatus(buildStatus.name());
|
||||||
@ -169,7 +169,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
|||||||
// 等待一定时间后再检查
|
// 等待一定时间后再检查
|
||||||
Thread.sleep(BUILD_POLL_INTERVAL * 1000L);
|
Thread.sleep(BUILD_POLL_INTERVAL * 1000L);
|
||||||
|
|
||||||
// ✅ 1. 增量拉取并保存 Jenkins 构建日志
|
// 1. 增量拉取并保存 Jenkins 构建日志
|
||||||
try {
|
try {
|
||||||
JenkinsConsoleOutputResponse consoleOutput = jenkinsServiceIntegration.getConsoleOutput(externalSystem, jobName, buildNumber, logOffset);
|
JenkinsConsoleOutputResponse consoleOutput = jenkinsServiceIntegration.getConsoleOutput(externalSystem, jobName, buildNumber, logOffset);
|
||||||
|
|
||||||
@ -192,17 +192,17 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
|||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SUCCESS:
|
case SUCCESS:
|
||||||
// ✅ 构建成功,拉取剩余日志后返回状态
|
// 构建成功,拉取剩余日志后返回状态
|
||||||
log.info("Jenkins build succeeded: job={}, buildNumber={}", jobName, buildNumber);
|
log.info("Jenkins build succeeded: job={}, buildNumber={}", jobName, buildNumber);
|
||||||
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
|
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
|
||||||
logInfo(String.format("✅ Jenkins 构建成功: buildNumber=%d", buildNumber));
|
logInfo(String.format("✅ Jenkins 构建成功: buildNumber=%d", buildNumber));
|
||||||
return status;
|
return status;
|
||||||
case FAILURE:
|
case FAILURE:
|
||||||
// ❌ 构建失败,拉取剩余日志后抛出异常
|
// 构建失败,拉取剩余日志后抛出异常
|
||||||
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
|
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
|
||||||
throw new RuntimeException(String.format("Jenkins build failed: job=%s, buildNumber=%d", jobName, buildNumber));
|
throw new RuntimeException(String.format("Jenkins build failed: job=%s, buildNumber=%d", jobName, buildNumber));
|
||||||
case ABORTED:
|
case ABORTED:
|
||||||
// ❌ 构建被取消,拉取剩余日志后抛出异常
|
// 构建被取消,拉取剩余日志后抛出异常
|
||||||
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
|
fetchRemainingLogs(execution, externalSystem, jobName, buildNumber, logOffset);
|
||||||
throw new RuntimeException(String.format("Jenkins build was aborted: job=%s, buildNumber=%d", jobName, buildNumber));
|
throw new RuntimeException(String.format("Jenkins build was aborted: job=%s, buildNumber=%d", jobName, buildNumber));
|
||||||
case IN_PROGRESS:
|
case IN_PROGRESS:
|
||||||
@ -210,7 +210,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
|||||||
attempts++;
|
attempts++;
|
||||||
break;
|
break;
|
||||||
case NOT_FOUND:
|
case NOT_FOUND:
|
||||||
// ❌ 构建记录丢失,抛出异常
|
// 构建记录丢失,抛出异常
|
||||||
throw new RuntimeException(String.format("Jenkins build not found: job=%s, buildNumber=%d", jobName, buildNumber));
|
throw new RuntimeException(String.format("Jenkins build not found: job=%s, buildNumber=%d", jobName, buildNumber));
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} 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("Build status polling was interrupted", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new RuntimeException(String.format("Jenkins build timed out after %d minutes: job=%s, buildNumber=%d",
|
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));
|
||||||
MAX_BUILD_POLLS * BUILD_POLL_INTERVAL / 60, jobName, buildNumber));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user