mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-20 23:20:09 +08:00
parent
6c0b475c15
commit
3499506089
6
main.go
6
main.go
@ -92,6 +92,11 @@ func main() {
|
|||||||
Usage: "execute commands",
|
Usage: "execute commands",
|
||||||
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT",
|
EnvVar: "PLUGIN_SCRIPT,SSH_SCRIPT",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "script.stop",
|
||||||
|
Usage: "stop script after first failure",
|
||||||
|
EnvVar: "PLUGIN_SCRIPT_STOP",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "proxy.ssh-key",
|
Name: "proxy.ssh-key",
|
||||||
Usage: "private ssh key of proxy",
|
Usage: "private ssh key of proxy",
|
||||||
@ -197,6 +202,7 @@ func run(c *cli.Context) error {
|
|||||||
Timeout: c.Duration("timeout"),
|
Timeout: c.Duration("timeout"),
|
||||||
CommandTimeout: c.Int("command.timeout"),
|
CommandTimeout: c.Int("command.timeout"),
|
||||||
Script: c.StringSlice("script"),
|
Script: c.StringSlice("script"),
|
||||||
|
ScriptStop: c.Bool("script.stop"),
|
||||||
Secrets: c.StringSlice("secrets"),
|
Secrets: c.StringSlice("secrets"),
|
||||||
Envs: c.StringSlice("envs"),
|
Envs: c.StringSlice("envs"),
|
||||||
Debug: c.Bool("debug"),
|
Debug: c.Bool("debug"),
|
||||||
|
24
plugin.go
24
plugin.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -9,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/appleboy/easyssh-proxy"
|
"github.com/appleboy/easyssh-proxy"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -31,6 +31,7 @@ type (
|
|||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
CommandTimeout int
|
CommandTimeout int
|
||||||
Script []string
|
Script []string
|
||||||
|
ScriptStop bool
|
||||||
Secrets []string
|
Secrets []string
|
||||||
Envs []string
|
Envs []string
|
||||||
Proxy easyssh.DefaultConfig
|
Proxy easyssh.DefaultConfig
|
||||||
@ -82,7 +83,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Config.Script = append(env, p.Config.Script...)
|
p.Config.Script = append(env, p.scriptCommands()...)
|
||||||
|
|
||||||
if p.Config.Debug {
|
if p.Config.Debug {
|
||||||
p.log(host, "======ENV======")
|
p.log(host, "======ENV======")
|
||||||
@ -179,3 +180,22 @@ func (p Plugin) Exec() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Plugin) scriptCommands() []string {
|
||||||
|
numCommands := len(p.Config.Script)
|
||||||
|
if p.Config.ScriptStop {
|
||||||
|
numCommands *= 2
|
||||||
|
}
|
||||||
|
|
||||||
|
commands := make([]string, numCommands)
|
||||||
|
|
||||||
|
for _, cmd := range p.Config.Script {
|
||||||
|
if p.Config.ScriptStop {
|
||||||
|
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
|
||||||
|
}
|
||||||
|
|
||||||
|
commands = append(commands, cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
return commands
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user