mirror of
https://github.com/hashicorp/packer.git
synced 2026-05-28 04:35:38 -04:00
allow to set ExecutionPolicy to none for powershell provisioner
this has the effect to not wrap the command, which will allow to know the exit status of a command in docker
This commit is contained in:
parent
e96409954a
commit
e62aba3788
3 changed files with 19 additions and 13 deletions
|
|
@ -10,13 +10,14 @@ import (
|
|||
type ExecutionPolicy int
|
||||
|
||||
const (
|
||||
Bypass ExecutionPolicy = 0
|
||||
AllSigned ExecutionPolicy = 1
|
||||
Default ExecutionPolicy = 2
|
||||
RemoteSigned ExecutionPolicy = 3
|
||||
Restricted ExecutionPolicy = 4
|
||||
Undefined ExecutionPolicy = 5
|
||||
Unrestricted ExecutionPolicy = 6
|
||||
Bypass ExecutionPolicy = iota
|
||||
AllSigned
|
||||
Default
|
||||
RemoteSigned
|
||||
Restricted
|
||||
Undefined
|
||||
Unrestricted
|
||||
None // not set
|
||||
)
|
||||
|
||||
func (ep *ExecutionPolicy) Decode(v interface{}) (err error) {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
const _ExecutionPolicyName = "BypassAllSignedDefaultRemoteSignedRestrictedUndefinedUnrestricted"
|
||||
const _ExecutionPolicyName = "BypassAllSignedDefaultRemoteSignedRestrictedUndefinedUnrestrictedNone"
|
||||
|
||||
var _ExecutionPolicyIndex = [...]uint8{0, 6, 15, 22, 34, 44, 53, 65}
|
||||
var _ExecutionPolicyIndex = [...]uint8{0, 6, 15, 22, 34, 44, 53, 65, 69}
|
||||
|
||||
func (i ExecutionPolicy) String() string {
|
||||
if i < 0 || i >= ExecutionPolicy(len(_ExecutionPolicyIndex)-1) {
|
||||
|
|
@ -18,7 +18,7 @@ func (i ExecutionPolicy) String() string {
|
|||
return _ExecutionPolicyName[_ExecutionPolicyIndex[i]:_ExecutionPolicyIndex[i+1]]
|
||||
}
|
||||
|
||||
var _ExecutionPolicyValues = []ExecutionPolicy{0, 1, 2, 3, 4, 5, 6}
|
||||
var _ExecutionPolicyValues = []ExecutionPolicy{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
|
||||
var _ExecutionPolicyNameToValueMap = map[string]ExecutionPolicy{
|
||||
_ExecutionPolicyName[0:6]: 0,
|
||||
|
|
@ -28,6 +28,7 @@ var _ExecutionPolicyNameToValueMap = map[string]ExecutionPolicy{
|
|||
_ExecutionPolicyName[34:44]: 4,
|
||||
_ExecutionPolicyName[44:53]: 5,
|
||||
_ExecutionPolicyName[53:65]: 6,
|
||||
_ExecutionPolicyName[65:69]: 7,
|
||||
}
|
||||
|
||||
// ExecutionPolicyString retrieves an enum value from the enum constants string name.
|
||||
|
|
|
|||
|
|
@ -87,10 +87,14 @@ type EnvVarsTemplate struct {
|
|||
}
|
||||
|
||||
func (p *Provisioner) defaultExecuteCommand() string {
|
||||
return `powershell -executionpolicy ` + p.config.ExecutionPolicy.String() +
|
||||
` "& { if (Test-Path variable:global:ProgressPreference)` +
|
||||
baseCmd := `& { if (Test-Path variable:global:ProgressPreference)` +
|
||||
`{set-variable -name variable:global:ProgressPreference -value 'SilentlyContinue'};` +
|
||||
`. {{.Vars}}; &'{{.Path}}'; exit $LastExitCode }"`
|
||||
`. {{.Vars}}; &'{{.Path}}'; exit $LastExitCode }`
|
||||
if p.config.ExecutionPolicy == None {
|
||||
return baseCmd
|
||||
} else {
|
||||
return fmt.Sprintf(`powershell -executionpolicy %s "%s"`, p.config.ExecutionPolicy, baseCmd)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue