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:
Vladimir Sigalkin
2023-04-13 04:13:07 +03:00
committed by GitHub
parent 4aabfc90dd
commit 6464d9999f
2 changed files with 15 additions and 1 deletions
+7 -1
View File
@@ -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