diff --git a/cli/azd/.vscode/cspell.yaml b/cli/azd/.vscode/cspell.yaml index 97044171071..668b9562fe9 100644 --- a/cli/azd/.vscode/cspell.yaml +++ b/cli/azd/.vscode/cspell.yaml @@ -15,6 +15,7 @@ words: - Retryable - runcontext - unmarshals + - noprofile - usgovcloudapi languageSettings: - languageId: go diff --git a/cli/azd/cmd/hooks.go b/cli/azd/cmd/hooks.go index 09ef37c6b2b..0c57e11d7ea 100644 --- a/cli/azd/cmd/hooks.go +++ b/cli/azd/cmd/hooks.go @@ -236,6 +236,7 @@ func (hra *hooksRunAction) execHook( defer hra.console.StopPreviewer(ctx, false) runOptions := &tools.ExecOptions{StdOut: previewer} + err := hooksRunner.RunHooks(ctx, hookType, runOptions, commandName) if err != nil { return err diff --git a/cli/azd/pkg/ext/hooks_runner.go b/cli/azd/pkg/ext/hooks_runner.go index 2d87378568b..ff93e38fc28 100644 --- a/cli/azd/pkg/ext/hooks_runner.go +++ b/cli/azd/pkg/ext/hooks_runner.go @@ -159,6 +159,14 @@ func (h *HooksRunner) execHook(ctx context.Context, hookConfig *HookConfig, opti defer h.console.StopPreviewer(ctx, false) } + var isRunWithNoProfile bool + if hookConfig.Shell == "pwsh" { + if hookConfig.Run != "" { + isRunWithNoProfile = strings.Contains(strings.ToLower(hookConfig.Run), "-noprofile") + } + } + options.IsRunWithNoProfile = isRunWithNoProfile + log.Printf("Executing script '%s'\n", hookConfig.path) res, err := script.Execute(ctx, hookConfig.path, *options) if err != nil { diff --git a/cli/azd/pkg/tools/powershell/powershell.go b/cli/azd/pkg/tools/powershell/powershell.go index ca9fad66290..645481b78ec 100644 --- a/cli/azd/pkg/tools/powershell/powershell.go +++ b/cli/azd/pkg/tools/powershell/powershell.go @@ -25,7 +25,14 @@ type powershellScript struct { // Executes the specified powershell script // When interactive is true will attach to stdin, stdout & stderr func (bs *powershellScript) Execute(ctx context.Context, path string, options tools.ExecOptions) (exec.RunResult, error) { - runArgs := exec.NewRunArgs("pwsh", path). + cmdConfig := " -NoProfile" + normalCmd := "pwsh" + + if options.IsRunWithNoProfile { + normalCmd += cmdConfig + } + + runArgs := exec.NewRunArgs(normalCmd, path). WithCwd(bs.cwd). WithEnv(bs.envVars). WithShell(true) diff --git a/cli/azd/pkg/tools/script.go b/cli/azd/pkg/tools/script.go index f111db99400..adda683df4f 100644 --- a/cli/azd/pkg/tools/script.go +++ b/cli/azd/pkg/tools/script.go @@ -9,8 +9,9 @@ import ( // ExecOptions provide configuration for how scripts are executed type ExecOptions struct { - Interactive *bool - StdOut io.Writer + Interactive *bool + StdOut io.Writer + IsRunWithNoProfile bool } // Utility to easily execute a bash script across platforms