use ValidExitCode in provisioners windows-shell, powershell and shell
This commit is contained in:
parent
f0a23bb81d
commit
72e5ae9ddc
|
@ -146,10 +146,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
p.config.Vars = make([]string, 0)
|
p.config.Vars = make([]string, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.config.ValidExitCodes == nil {
|
|
||||||
p.config.ValidExitCodes = []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var errs error
|
var errs error
|
||||||
if p.config.Script != "" && len(p.config.Scripts) > 0 {
|
if p.config.Script != "" && len(p.config.Scripts) > 0 {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
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
|
// Close the original file since we copied it
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
// Check exit code against allowed codes (likely just 0)
|
if err := p.config.ValidExitCode(cmd.ExitStatus); err != nil {
|
||||||
validExitCode := false
|
return err
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -335,10 +335,11 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
||||||
return fmt.Errorf("Script disconnected unexpectedly. " +
|
return fmt.Errorf("Script disconnected unexpectedly. " +
|
||||||
"If you expected your script to disconnect, i.e. from a " +
|
"If you expected your script to disconnect, i.e. from a " +
|
||||||
"restart, you can try adding `\"expect_disconnect\": true` " +
|
"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 {
|
} else if err := p.config.ValidExitCode(cmd.ExitStatus); err != nil {
|
||||||
return fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.config.SkipClean {
|
if !p.config.SkipClean {
|
||||||
|
|
|
@ -96,10 +96,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
|
||||||
p.config.Vars = make([]string, 0)
|
p.config.Vars = make([]string, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(p.config.ValidExitCodes) == 0 {
|
|
||||||
p.config.ValidExitCodes = []int{0}
|
|
||||||
}
|
|
||||||
|
|
||||||
var errs error
|
var errs error
|
||||||
if p.config.Script != "" && len(p.config.Scripts) > 0 {
|
if p.config.Script != "" && len(p.config.Scripts) > 0 {
|
||||||
errs = packer.MultiErrorAppend(errs,
|
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
|
// Close the original file since we copied it
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
// Check exit code against allowed codes (likely just 0)
|
if err := p.config.ValidExitCode(cmd.ExitStatus); err != nil {
|
||||||
validExitCode := false
|
return err
|
||||||
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