[ Agent ] [ Executor ] 优化Executor部分的代码 - 2
This commit is contained in:
@@ -79,28 +79,31 @@ func PipeLineCommandExecutor(pipeLineCommand [][]string) ([]string, error) {
|
|||||||
var output []byte
|
var output []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for i, command := range pipeLineCommand {
|
for _, pipeCommand := range pipeLineCommand {
|
||||||
|
if len(pipeCommand) == 0 {
|
||||||
cmd := exec.Command(command[0], command[1:]...)
|
continue
|
||||||
cmd.Stdin = bytes.NewReader(output)
|
|
||||||
|
|
||||||
output, err = cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
return strings.Split(string(output), "\n"), err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == len(pipeLineCommand)-1 {
|
command := exec.Command(pipeCommand[0], pipeCommand[1:]...)
|
||||||
return strings.Split(string(output), "\n"), nil
|
if len(output) > 0 {
|
||||||
|
command.Stdin = bytes.NewBuffer(output)
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err = command.Output()
|
||||||
|
if err != nil {
|
||||||
|
log.ErrorF("Pipeline Command Exec Error => %v", err.Error())
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return []string{}, nil
|
|
||||||
|
return []string{string(output)}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) {
|
func MultiLineCommandExecutor(multiLineCommandExecutor [][]string) ([]string, error) {
|
||||||
|
|
||||||
var res []string
|
var res []string
|
||||||
for _, singleLineCommand := range multiLineCommandExecutor {
|
for _, singleLineCommand := range multiLineCommandExecutor {
|
||||||
singleLogs, err := SingleLineCommandExecutor(singleLineCommand)
|
singleLogs, err := AllOutputCommandExecutor(singleLineCommand)
|
||||||
res = append(res, singleLogs...)
|
res = append(res, singleLogs...)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func AllOutputCommandExecutor(singleLineCommand []string) ([]string, error) {
|
|||||||
log.ErrorF("command %v runtime error => %v", singleLineCommand, err)
|
log.ErrorF("command %v runtime error => %v", singleLineCommand, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSlice = append(resultSlice, "↓↓↓ 命令 输出 如下 ↓↓↓")
|
resultSlice = append(resultSlice, fmt.Sprintf("命令为 => %v", singleLineCommand), "↓↓↓ 命令 输出 如下 ↓↓↓")
|
||||||
resultSlice = collectOutput(stdout, resultSlice)
|
resultSlice = collectOutput(stdout, resultSlice)
|
||||||
resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓")
|
resultSlice = append(resultSlice, "↓↓↓ 命令 错误 如下 ↓↓↓")
|
||||||
resultSlice = collectOutput(stderr, resultSlice)
|
resultSlice = collectOutput(stderr, resultSlice)
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class ExecutionController {
|
|||||||
null,
|
null,
|
||||||
commandList,
|
commandList,
|
||||||
completeCommandList,
|
completeCommandList,
|
||||||
false,
|
true,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,10 @@ package io.wdd.server;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class ServerApplicationTests {
|
class ServerApplicationTests {
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
AsyncExecutionService asyncExecutionService;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCoreExecutionCompleteScript() {
|
void testCoreExecutionCompleteScript() {
|
||||||
|
|||||||
Reference in New Issue
Block a user