windows-shell provisioner: allow to pass ValidExitCodes
This commit is contained in:
parent
721cad1012
commit
8fea9439f8
|
@ -63,6 +63,11 @@ type Config struct {
|
|||
// inside the `ExecuteCommand` template.
|
||||
EnvVarFormat string
|
||||
|
||||
// Valid Exit Codes - 0 is not always the only valid error code! See
|
||||
// http://www.symantec.com/connect/articles/windows-system-error-codes-exit-codes-description
|
||||
// for examples such as 3010 - "The requested operation is successful.
|
||||
ValidExitCodes []int `mapstructure:"valid_exit_codes"`
|
||||
|
||||
ctx interpolate.Context
|
||||
}
|
||||
|
||||
|
@ -117,6 +122,10 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
|||
p.config.Vars = make([]string, 0)
|
||||
}
|
||||
|
||||
if len(p.config.ValidExitCodes) == 0 {
|
||||
p.config.ValidExitCodes = []int{0}
|
||||
}
|
||||
|
||||
var errs error
|
||||
if p.config.Script != "" && len(p.config.Scripts) > 0 {
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
|
@ -243,8 +252,17 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
|||
// Close the original file since we copied it
|
||||
f.Close()
|
||||
|
||||
if cmd.ExitStatus != 0 {
|
||||
return fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus)
|
||||
// Check exit code against allowed codes (likely just 0)
|
||||
validExitCode := false
|
||||
for _, v := range p.config.ValidExitCodes {
|
||||
if cmd.ExitStatus == v {
|
||||
validExitCode = true
|
||||
}
|
||||
}
|
||||
if !validExitCode {
|
||||
return fmt.Errorf(
|
||||
"Script exited with non-zero exit status: %d. Allowed exit codes are: %v",
|
||||
cmd.ExitStatus, p.config.ValidExitCodes)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue