[ Agent ] [ Executor ] - 修改底层执行返回逻辑
This commit is contained in:
@@ -24,12 +24,12 @@ var log = logger2.Log
|
||||
|
||||
var AgentOsOperatorCache = &AgentOsOperator{}
|
||||
|
||||
func Execute(em *ExecutionMessage) ([]string, error) {
|
||||
func Execute(em *ExecutionMessage) (bool, []string) {
|
||||
|
||||
var resultLog []string
|
||||
var err error
|
||||
var realCommand [][]string
|
||||
ok := true
|
||||
executionContent := em.ExecutionType + "==" + strings.Join(em.FuncContent, "")
|
||||
|
||||
log.DebugF("em message is => %#v", em)
|
||||
|
||||
@@ -40,9 +40,6 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
||||
} else {
|
||||
ok, resultLog = AgentOsOperatorCache.Exec(em.FuncContent[0])
|
||||
}
|
||||
if ok {
|
||||
return resultLog, nil
|
||||
}
|
||||
|
||||
} else if strings.HasPrefix(em.ExecutionType, "APP") {
|
||||
// app function
|
||||
@@ -51,39 +48,35 @@ func Execute(em *ExecutionMessage) ([]string, error) {
|
||||
} else {
|
||||
ok, resultLog = AgentOsOperatorCache.Deploy(em.FuncContent[0])
|
||||
}
|
||||
if ok {
|
||||
return resultLog, nil
|
||||
} else {
|
||||
return resultLog, nil
|
||||
}
|
||||
|
||||
} else {
|
||||
// shell command
|
||||
if em.PipeLineCommand != nil && len(em.PipeLineCommand) != 0 {
|
||||
// 管道命令
|
||||
resultLog, err = PipeLineCommandExecutor(em.PipeLineCommand)
|
||||
realCommand = em.PipeLineCommand
|
||||
executionContent = fmt.Sprintf("%v", em.PipeLineCommand)
|
||||
} else if em.MultiLineCommand != nil && len(em.MultiLineCommand) != 0 {
|
||||
// 多行命令
|
||||
resultLog, err = MultiLineCommandExecutor(em.MultiLineCommand)
|
||||
realCommand = em.MultiLineCommand
|
||||
executionContent = fmt.Sprintf("%v", em.MultiLineCommand)
|
||||
} else {
|
||||
// 单行命令
|
||||
resultLog, err = FormatAllCommandExecutor(em.SingleLineCommand)
|
||||
realCommand = [][]string{em.SingleLineCommand}
|
||||
executionContent = fmt.Sprintf("%v", em.SingleLineCommand)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 归一化错误和日志
|
||||
if err != nil {
|
||||
resultLog = append(resultLog, "↓↓↓ 命令 Error 如下 ↓↓↓", err.Error())
|
||||
resultLog = append(resultLog, " 命令执行错误如下 ", err.Error())
|
||||
}
|
||||
|
||||
resultLog = append(resultLog, fmt.Sprintf("命令 %s 执行结果为 %b", executionContent, ok))
|
||||
// debug
|
||||
commandResult := fmt.Sprintf("Excution Comand are=> %v, Executor Result: %v", realCommand, resultLog)
|
||||
log.Debug(commandResult)
|
||||
log.DebugF("%v", resultLog)
|
||||
|
||||
return resultLog, err
|
||||
return ok, resultLog
|
||||
}
|
||||
|
||||
func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
||||
|
||||
@@ -131,8 +131,8 @@ func executorOMHandler(octopusMessage *OctopusMessage) {
|
||||
}
|
||||
|
||||
// 执行命令
|
||||
resultLog, err := executor.Execute(executionMessage)
|
||||
if err == nil {
|
||||
ok, resultLog := executor.Execute(executionMessage)
|
||||
if ok {
|
||||
octopusMessage.ResultCode = "200"
|
||||
} else {
|
||||
octopusMessage.ResultCode = "300"
|
||||
|
||||
Reference in New Issue
Block a user