diff --git a/builder/amazonebs/builder.go b/builder/amazonebs/builder.go index 47f3a36aa..9e431faa2 100644 --- a/builder/amazonebs/builder.go +++ b/builder/amazonebs/builder.go @@ -100,21 +100,7 @@ func (b *Builder) Prepare(raw interface{}) error { return nil } -func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { - // Basic sanity checks. These are panics now because the Prepare - // method should verify these exist and such. - if b.config.AccessKey == "" { - panic("access key not filled in") - } - - if b.config.SecretKey == "" { - panic("secret key not filled in") - } - - if b.config.Region == "" { - panic("region not filled in") - } - +func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { region, ok := aws.Regions[b.config.Region] if !ok { panic("region not found") @@ -147,11 +133,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer // If there are no AMIs, then jsut return if _, ok := state["amis"]; !ok { - return nil + return nil, nil } // Build the artifact and return it - return &artifact{state["amis"].(map[string]string)} + return &artifact{state["amis"].(map[string]string)}, nil } func (b *Builder) Cancel() { diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index 725d6d94f..b73cf6695 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -169,7 +169,7 @@ func (b *Builder) Prepare(raw interface{}) error { return nil } -func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { +func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { steps := []multistep.Step{ new(stepDownloadISO), new(stepPrepareOutputDir), @@ -197,7 +197,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer b.runner = &multistep.BasicRunner{Steps: steps} b.runner.Run(state) - return nil + return nil, nil } func (b *Builder) Cancel() { diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index 5a824bd43..b502083df 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -184,7 +184,7 @@ func (b *Builder) Prepare(raw interface{}) error { return nil } -func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { +func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { // Seed the random number generator rand.Seed(time.Now().UTC().UnixNano()) @@ -216,11 +216,11 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer // If we were interrupted or cancelled, then just exit. if _, ok := state[multistep.StateCancelled]; ok { - return nil + return nil, nil } if _, ok := state[multistep.StateHalted]; ok { - return nil + return nil, nil } // Compile the artifact list @@ -231,11 +231,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer } if err := filepath.Walk(b.config.OutputDir, visit); err != nil { - ui.Error(fmt.Sprintf("Error collecting result files: %s", err)) - return nil + return nil, err } - return &Artifact{b.config.OutputDir, files} + return &Artifact{b.config.OutputDir, files}, nil } func (b *Builder) Cancel() { diff --git a/command/build/command.go b/command/build/command.go index ba15b1cd3..de5c6d3d5 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -139,10 +139,16 @@ func (c Command) Run(env packer.Environment, args []string) int { go func(b packer.Build) { defer wg.Done() + var err error log.Printf("Starting build run: %s", b.Name()) ui := buildUis[b.Name()] - artifacts[b.Name()] = b.Run(ui, env.Cache()) - ui.Say("Build finished.") + artifacts[b.Name()], err = b.Run(ui, env.Cache()) + + if err != nil { + ui.Error(fmt.Sprintf("Build errored: %s", err)) + } else { + ui.Say("Build finished.") + } }(b) } diff --git a/packer/plugin/builder.go b/packer/plugin/builder.go index cb37b5bc2..18a4061c2 100644 --- a/packer/plugin/builder.go +++ b/packer/plugin/builder.go @@ -19,7 +19,7 @@ func (b *cmdBuilder) Prepare(config interface{}) error { return b.builder.Prepare(config) } -func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact { +func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { defer func() { r := recover() b.checkExit(r, nil) diff --git a/packer/plugin/builder_test.go b/packer/plugin/builder_test.go index bb8e7b00b..ab24a13f8 100644 --- a/packer/plugin/builder_test.go +++ b/packer/plugin/builder_test.go @@ -12,8 +12,8 @@ func (helperBuilder) Prepare(interface{}) error { return nil } -func (helperBuilder) Run(packer.Ui, packer.Hook, packer.Cache) packer.Artifact { - return nil +func (helperBuilder) Run(packer.Ui, packer.Hook, packer.Cache) (packer.Artifact, error) { + return nil, nil } func (helperBuilder) Cancel() {}