代码修改

This commit is contained in:
even 2025-06-09 16:47:17 +08:00
parent 622567d385
commit 7b40579064
5 changed files with 62 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;

View File

@ -98,7 +98,6 @@ public class PipelineRunContext extends BaseRunContext{
// 入库保存
contextManager.toHistory(getContextDef().getId());
}
callParentChange(stateEnum);
} else {
log.error("非法状态扭转直接忽略,{},{}",curr,stateEnum);
}

View File

@ -2,25 +2,80 @@ package cd.casic.ci.process.engine.worker;
import cd.casic.ci.process.common.WorkAtom;
import cd.casic.ci.process.dal.resp.resource.ResourceFindResp;
import cd.casic.ci.process.engine.constant.DIYImageExecuteCommandConstant;
import cd.casic.ci.process.engine.runContext.TaskRunContext;
import cd.casic.ci.process.engine.worker.base.BaseWorker;
import cd.casic.ci.process.engine.worker.base.SshWorker;
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
import cd.casic.ci.process.process.dataObject.pipeline.PipPipeline;
import cd.casic.ci.process.process.dataObject.resource.PipResourceMachine;
import cd.casic.ci.process.process.dataObject.task.PipTask;
import cd.casic.ci.process.util.CryptogramUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/**
* 自定义编译
* */
@Slf4j
@WorkAtom(taskType = "CUSTOM_COMPILE")
public class CustomCompilerWorker extends BaseWorker {
public class CustomCompilerWorker extends SshWorker {
@Override
public void execute(TaskRunContext context) {
PipBaseElement contextDef = context.getContextDef();
String id = contextDef.getId();
log.info("==============触发worker执行========");
log.info("==========运行context{}===========", JSON.toJSONString(context));
int statusCode = -1;
Map<String, Object> localVariables = context.getLocalVariables();
if (context.getContextDef() instanceof PipTask taskDef) {
log.info(taskDef.getTaskName());
Map<String, Object> taskProperties = taskDef.getTaskProperties();
Object commandScriptObj = taskProperties.get(DIYImageExecuteCommandConstant.COMMAND_SCRIPT);
Object machineIdObj = taskProperties.get(DIYImageExecuteCommandConstant.MACHINE_ID);
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
Long machineId = null;
try {
machineId=Long.valueOf(String.valueOf(machineIdObj));
} catch (NumberFormatException e) {
log.error("缺少参数:{}",DIYImageExecuteCommandConstant.MACHINE_ID);
toBadEnding();
}
if (StringUtils.isEmpty(commandScript) ||machineIdObj == null) {
// 缺少参数
toBadEnding();
}
try {
//将节点的配置信息反编译成对象
log.info("构建脚本" + commandScript);
//如果machineId为0则说明该节点没有配置机器则使用开始节点的机器
//获取机器
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
String resourceId = pipeline.getResourceId();
ResourceFindResp resourceById = getResourceManagerService().findResourceById(resourceId);
PipResourceMachine resourceMachine = resourceById.getResourceMachine();
//TODO 得改一下
statusCode = shell(resourceMachine, CryptogramUtil.doDecrypt(resourceMachine.getPassword()),context,
"echo \"编译命令执行\"",
commandScript
);
} catch (Exception e) {
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
log.error("执行ssh失败:",e);
append(context,errorMessage);
toBadEnding();
}
if (statusCode == 0) {
log.info("节点执行完成");
} else {
log.error("节点执行失败");
}
localVariables.put(DIYImageExecuteCommandConstant.STATUS_CODE,statusCode);
}
}
}

View File

@ -33,7 +33,7 @@ public class TestCaseGenerationWorker extends SshWorker {
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
String machineId = pipeline.getMachineId();
if (StringUtils.isEmpty(commandScript)||StringUtils.isEmpty(machineId)) {
if (StringUtils.isEmpty(commandScript)) {
// 缺少参数
toBadEnding();
}

View File

@ -59,7 +59,6 @@ public abstract class BaseWorker implements Runnable{
}
doWorker(contextKey);
}
public void doWorker(String contextKey){
BaseRunContext context = contextManager.getContext(contextKey);
if (context instanceof TaskRunContext taskRunContext){