diff --git a/pkg/exec/service.go b/pkg/exec/service.go index cdb16e8..dd5f44a 100644 --- a/pkg/exec/service.go +++ b/pkg/exec/service.go @@ -8,6 +8,7 @@ import ( "log" "os/exec" "path" + "strings" "github.com/jinzhu/gorm" "github.com/yuedun/zhuque/db" @@ -240,8 +241,14 @@ func (u *execService) PostDeploy(deployConfig project.DeployConfig) ([]byte, err for _, host := range deployConfig.Host { go func(host string, ch chan []byte) { // ssh user@remoteNode "cd /home ; ls" - // 用户名,IP,项目目录,前置命令, 命令 - ssh := fmt.Sprintf("ssh %s@%s \"cd %s; %s; %s\"", deployConfig.User, host, deployConfig.Path, deployConfig.PreDeploy, deployConfig.PostDeploy) + // 用户名,IP,项目目录, 命令 + ssh := fmt.Sprintf("ssh %s@%s \"cd %s; %s\"", deployConfig.User, host, deployConfig.Path, deployConfig.PostDeploy) + if deployConfig.PreDeploy != "" { + // 用户名,IP,项目目录,前置命令, 命令 + po := strings.Index(deployConfig.PreDeploy, ";") + preDeploy := deployConfig.PreDeploy[:po] + ssh = fmt.Sprintf("ssh %s@%s \"cd %s; %s; %s\"", deployConfig.User, host, deployConfig.Path, preDeploy, deployConfig.PostDeploy) + } cmdput, err := u.CmdSync(ssh) if err != nil { log.Println("postDeploy过程 远程命令执行失败:", err) diff --git a/tests/cmd_test.go b/tests/cmd_test.go index f9560a4..52421e2 100644 --- a/tests/cmd_test.go +++ b/tests/cmd_test.go @@ -74,6 +74,13 @@ func TestFile(t *testing.T) { } } +func TestSubstr(t *testing.T) { + str := "删掉了改好aaa中文;b中文二bb;" + po := strings.LastIndexAny(str, ";") + ss := str[:po] + t.Log(po, ss) +} + func TestChan(t *testing.T) { ch := make(chan []byte, 3) // errch := make(chan error, 3)