mirror of
https://github.com/appleboy/drone-ssh.git
synced 2026-06-04 18:24:01 +08:00
chore: flexible configuration of environment value transfer (#235)
**Reason:**
I have to use drone-ssh to work with Windows SSH. Initially, drone-ssh is written so that it transmits environment variables through the `export` command. Which makes it unsuitable for working with Power Shell.
**Solution:**
I have added a new option to configure environment variable commands formatting, with default value: `export {NAME}={VALUE}`. When I use drone-ssh with PowerShell I set this option like this: `$env:{NAME} = {VALUE}`.
This commit is contained in:
committed by
GitHub
parent
4aabfc90dd
commit
6464d9999f
@@ -40,6 +40,7 @@ type (
|
||||
Sync bool
|
||||
Ciphers []string
|
||||
UseInsecureCipher bool
|
||||
EnvsFormat string
|
||||
}
|
||||
|
||||
// Plugin structure
|
||||
@@ -103,7 +104,7 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
|
||||
for _, key := range p.Config.Envs {
|
||||
key = strings.ToUpper(key)
|
||||
if val, found := os.LookupEnv(key); found {
|
||||
env = append(env, "export "+key+"="+escapeArg(val))
|
||||
env = append(env, p.format(p.Config.EnvsFormat, "{NAME}", key, "{VALUE}", escapeArg(val)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +151,11 @@ loop:
|
||||
}
|
||||
}
|
||||
|
||||
func (p Plugin) format(format string, args ...string) string {
|
||||
r := strings.NewReplacer(args...)
|
||||
return r.Replace(format)
|
||||
}
|
||||
|
||||
func (p Plugin) log(host string, message ...interface{}) {
|
||||
if p.Writer == nil {
|
||||
p.Writer = os.Stdout
|
||||
|
||||
Reference in New Issue
Block a user