mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-05 22:02:49 +08:00
Expand DRONE* variables before uploading the script
This commit is contained in:
parent
e6d4fa77d1
commit
2daab5e1af
12
plugin.go
12
plugin.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -86,6 +87,17 @@ func (p Plugin) Exec() error {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expand DRONE env variables in script (like DRONE_DEPLOY_TO)
|
||||||
|
for index, _ := range p.Config.Script {
|
||||||
|
parts := strings.Split(p.Config.Script[index], " ")
|
||||||
|
for i, _ := range parts {
|
||||||
|
if strings.Contains(parts[i], "DRONE") {
|
||||||
|
parts[i] = os.ExpandEnv(parts[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.Config.Script[index] = strings.Join(parts, " ")
|
||||||
|
}
|
||||||
|
|
||||||
p.log(host, "commands: ", strings.Join(p.Config.Script, "\n"))
|
p.log(host, "commands: ", strings.Join(p.Config.Script, "\n"))
|
||||||
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
|
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user