feat(powershell): add non_interactive config option

Allows users to opt-out of -NonInteractive mode if they need to provide stdin input during provisioning.
Defaults to true to maintain existing behavior and prevent hangs in CI.

See #12637
This commit is contained in:
Vedant Madane 2026-05-20 05:05:11 +05:30
parent 83a613751d
commit 1da7e1e19f

View file

@ -119,6 +119,10 @@ type Config struct {
// Run pwsh.exe instead of powershell.exe - latest version of powershell.
UsePwsh bool `mapstructure:"use_pwsh"`
// Whether to run PowerShell in non-interactive mode.
// Defaults to true.
NonInteractive *bool `mapstructure:"non_interactive"`
ctx interpolate.Context
}
@ -129,15 +133,19 @@ type Provisioner struct {
}
func (p *Provisioner) defaultExecuteCommand() string {
nonInteractive := ""
if *p.config.NonInteractive {
nonInteractive = "-NonInteractive "
}
if p.config.ExecutionPolicy == ExecutionPolicyNone {
return `-file {{.Path}}`
return fmt.Sprintf(`%s-file {{.Path}}`, nonInteractive)
}
if p.config.UsePwsh {
return fmt.Sprintf(`pwsh -NonInteractive -executionpolicy %s -file {{.Path}}`, p.config.ExecutionPolicy)
return fmt.Sprintf(`pwsh %s-executionpolicy %s -file {{.Path}}`, nonInteractive, p.config.ExecutionPolicy)
} else {
return fmt.Sprintf(`powershell -NonInteractive -executionpolicy %s -file {{.Path}}`, p.config.ExecutionPolicy)
return fmt.Sprintf(`powershell %s-executionpolicy %s -file {{.Path}}`, nonInteractive, p.config.ExecutionPolicy)
}
}
@ -152,14 +160,19 @@ func (p *Provisioner) defaultScriptCommand() string {
baseCmd += `. {{.Vars}}; &'{{.Path}}'; exit $LastExitCode }`
nonInteractive := ""
if *p.config.NonInteractive {
nonInteractive = "-NonInteractive "
}
if p.config.ExecutionPolicy == ExecutionPolicyNone {
return baseCmd
return fmt.Sprintf(`%s-command "%s"`, nonInteractive, baseCmd)
}
if p.config.UsePwsh {
return fmt.Sprintf(`pwsh -NonInteractive -executionpolicy %s -command "%s"`, p.config.ExecutionPolicy, baseCmd)
return fmt.Sprintf(`pwsh %s-executionpolicy %s -command "%s"`, nonInteractive, p.config.ExecutionPolicy, baseCmd)
} else {
return fmt.Sprintf(`powershell -NonInteractive -executionpolicy %s "%s"`, p.config.ExecutionPolicy, baseCmd)
return fmt.Sprintf(`powershell %s-executionpolicy %s "%s"`, nonInteractive, p.config.ExecutionPolicy, baseCmd)
}
}
@ -196,6 +209,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.Inline = nil
}
if p.config.NonInteractive == nil {
b := true
p.config.NonInteractive = &b
}
if p.config.StartRetryTimeout == 0 {
p.config.StartRetryTimeout = 5 * time.Minute
}