use ValidExitCode in provisioners windows-shell, powershell and shell

This commit is contained in:
Adrien Delorme 2019-03-14 12:47:22 +01:00
parent f0a23bb81d
commit 72e5ae9ddc
3 changed files with 8 additions and 33 deletions

View File

@ -146,10 +146,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.Vars = make([]string, 0)
}
if p.config.ValidExitCodes == nil {
p.config.ValidExitCodes = []int{0}
}
var errs error
if p.config.Script != "" && len(p.config.Scripts) > 0 {
errs = packer.MultiErrorAppend(errs,
@ -274,17 +270,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
// Close the original file since we copied it
f.Close()
// 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)
if err := p.config.ValidExitCode(cmd.ExitStatus); err != nil {
return err
}
}

View File

@ -335,10 +335,11 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return fmt.Errorf("Script disconnected unexpectedly. " +
"If you expected your script to disconnect, i.e. from a " +
"restart, you can try adding `\"expect_disconnect\": true` " +
"to the shell provisioner parameters.")
"or `\"valid_exit_codes\": [0, 2300218]` to the shell " +
"provisioner parameters.")
}
} else if cmd.ExitStatus != 0 {
return fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus)
} else if err := p.config.ValidExitCode(cmd.ExitStatus); err != nil {
return err
}
if !p.config.SkipClean {

View File

@ -96,10 +96,6 @@ 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,
@ -226,17 +222,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
// Close the original file since we copied it
f.Close()
// 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)
if err := p.config.ValidExitCode(cmd.ExitStatus); err != nil {
return err
}
}