Skip to content

Commit 5011759

Browse files
committed
hooks: set expected environment when executing
During normal plugin execution (from the CLI), the CLI configures the plugin command it's about to execute in order to pass all environment variables on, as well as to set the ReExec env var that informs the plugin about how it was executed, and which plugins rely on to check whether they are being run standalone or not. This commit adds the same behavior to hook invocations, which is necessary for some plugins to know that they are not running standalone so that they expose their root command at the correct level. Signed-off-by: Laura Brehm <laurabrehm@hey.com>
1 parent c0cc22d commit 5011759

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

cli-plugins/manager/plugin.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package manager
22

33
import (
44
"encoding/json"
5+
"os"
56
"os/exec"
67
"path/filepath"
78
"regexp"
@@ -113,7 +114,10 @@ func (p *Plugin) RunHook(cmdName string, flags map[string]string) ([]byte, error
113114
return nil, wrapAsPluginError(err, "failed to marshall hook data")
114115
}
115116

116-
hookCmdOutput, err := exec.Command(p.Path, p.Name, HookSubcommandName, string(hDataBytes)).Output()
117+
pCmd := exec.Command(p.Path, p.Name, HookSubcommandName, string(hDataBytes))
118+
pCmd.Env = os.Environ()
119+
pCmd.Env = append(pCmd.Env, ReexecEnvvar+"="+os.Args[0])
120+
hookCmdOutput, err := pCmd.Output()
117121
if err != nil {
118122
return nil, wrapAsPluginError(err, "failed to execute plugin hook subcommand")
119123
}

0 commit comments

Comments
 (0)