Commit 47dcd473 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/build: Improved output when builds error

parent f4a5adf4
...@@ -164,6 +164,7 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -164,6 +164,7 @@ func (c Command) Run(env packer.Environment, args []string) int {
var interruptWg, wg sync.WaitGroup var interruptWg, wg sync.WaitGroup
interrupted := false interrupted := false
artifacts := make(map[string]packer.Artifact) artifacts := make(map[string]packer.Artifact)
errors := make(map[string]error)
for _, b := range builds { for _, b := range builds {
// Increment the waitgroup so we wait for this item to finish properly // Increment the waitgroup so we wait for this item to finish properly
wg.Add(1) wg.Add(1)
...@@ -187,15 +188,17 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -187,15 +188,17 @@ func (c Command) Run(env packer.Environment, args []string) int {
go func(b packer.Build) { go func(b packer.Build) {
defer wg.Done() defer wg.Done()
var err error name := b.Name()
log.Printf("Starting build run: %s", b.Name()) log.Printf("Starting build run: %s", name)
ui := buildUis[b.Name()] ui := buildUis[name]
artifacts[b.Name()], err = b.Run(ui, env.Cache()) artifact, err := b.Run(ui, env.Cache())
if err != nil { if err != nil {
ui.Error(fmt.Sprintf("Build errored: %s", err)) ui.Error(fmt.Sprintf("Build errored: %s", err))
errors[name] = err
} else { } else {
ui.Say("Build finished.") ui.Say("Build finished.")
artifacts[name] = artifact
} }
}(b) }(b)
...@@ -223,8 +226,15 @@ func (c Command) Run(env packer.Environment, args []string) int { ...@@ -223,8 +226,15 @@ func (c Command) Run(env packer.Environment, args []string) int {
return 1 return 1
} }
if len(errors) > 0 {
env.Ui().Error("\n==> Some builds didn't complete successfully and had errors:")
for name, err := range errors {
env.Ui().Error(fmt.Sprintf("--> %s: %s", name, err))
}
}
// Output all the artifacts // Output all the artifacts
env.Ui().Say("\n==> The build completed! The artifacts created were:") env.Ui().Say("\n==> Builds finished. The artifacts of successful builds are:")
for name, artifact := range artifacts { for name, artifact := range artifacts {
var message bytes.Buffer var message bytes.Buffer
fmt.Fprintf(&message, "--> %s: ", name) fmt.Fprintf(&message, "--> %s: ", name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment