mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
feat: added shell option
This commit is contained in:
parent
fc62fb377c
commit
f218df05e9
8
main.go
8
main.go
@ -197,6 +197,12 @@ func main() {
|
||||
Usage: "debug mode",
|
||||
EnvVars: []string{"PLUGIN_DEBUG", "DEBUG", "INPUT_DEBUG"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "shell",
|
||||
Usage: "shell on host",
|
||||
EnvVars: []string{"PLUGIN_HOST_SHELL"},
|
||||
Value: "bash",
|
||||
},
|
||||
}
|
||||
|
||||
// Override a template
|
||||
@ -242,6 +248,7 @@ func run(c *cli.Context) error {
|
||||
if s := c.String("script.string"); s != "" {
|
||||
scripts = append(scripts, s)
|
||||
}
|
||||
|
||||
plugin := Plugin{
|
||||
Config: Config{
|
||||
Key: c.String("ssh-key"),
|
||||
@ -261,6 +268,7 @@ func run(c *cli.Context) error {
|
||||
Sync: c.Bool("sync"),
|
||||
Ciphers: c.StringSlice("ciphers"),
|
||||
UseInsecureCipher: c.Bool("useInsecureCipher"),
|
||||
Shell: c.String("shell"),
|
||||
Proxy: easyssh.DefaultConfig{
|
||||
Key: c.String("proxy.ssh-key"),
|
||||
KeyPath: c.String("proxy.key-path"),
|
||||
|
@ -41,6 +41,7 @@ type (
|
||||
Sync bool
|
||||
Ciphers []string
|
||||
UseInsecureCipher bool
|
||||
Shell string
|
||||
}
|
||||
|
||||
// Plugin structure
|
||||
@ -99,11 +100,16 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
||||
p.log(host, strings.Join(p.Config.Script, "\n"))
|
||||
p.log(host, "======END======")
|
||||
|
||||
shell := p.Config.Shell
|
||||
env := []string{}
|
||||
for _, key := range p.Config.Envs {
|
||||
key = strings.ToUpper(key)
|
||||
if val, found := os.LookupEnv(key); found {
|
||||
env = append(env, "export "+key+"="+escapeArg(val))
|
||||
if shell == "bash" {
|
||||
env = append(env, "export "+key+"="+escapeArg(val))
|
||||
} else if shell == "powershell" {
|
||||
env = append(env, "$env:"+key+" = "+escapeArg(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user