mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-05-09 18:23:21 +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:
parent
4aabfc90dd
commit
6464d9999f
8
main.go
8
main.go
@ -196,6 +196,12 @@ func main() {
|
||||
Usage: "debug mode",
|
||||
EnvVars: []string{"PLUGIN_DEBUG", "INPUT_DEBUG"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "envs.format",
|
||||
Usage: "",
|
||||
EnvVars: []string{"PLUGIN_ENVS_FORMAT"},
|
||||
Value: "export {NAME}={VALUE}",
|
||||
},
|
||||
}
|
||||
|
||||
// Override a template
|
||||
@ -241,6 +247,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"),
|
||||
@ -256,6 +263,7 @@ func run(c *cli.Context) error {
|
||||
Script: scripts,
|
||||
ScriptStop: c.Bool("script.stop"),
|
||||
Envs: c.StringSlice("envs"),
|
||||
EnvsFormat: c.String("envs.format"),
|
||||
Debug: c.Bool("debug"),
|
||||
Sync: c.Bool("sync"),
|
||||
Ciphers: c.StringSlice("ciphers"),
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user