diff --git a/builder/internals.go b/builder/internals.go index 999c482a51..c315d2f949 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -556,8 +556,11 @@ func (b *Builder) run(c *daemon.Container) error { return err } - if err := <-errCh; err != nil { - return err + if b.Verbose { + // Block on reading output from container, stop on err or chan closed + if err := <-errCh; err != nil { + return err + } } // Wait for it to finish diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 738df91a21..e25c15d4cf 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -4921,3 +4921,38 @@ func TestBuildDotDotFile(t *testing.T) { } logDone("build - ..file") } + +func TestBuildNotVerbose(t *testing.T) { + defer deleteAllContainers() + defer deleteImages("verbose") + + ctx, err := fakeContext("FROM busybox\nENV abc=hi\nRUN echo $abc there", map[string]string{}) + if err != nil { + t.Fatal(err) + } + defer ctx.Close() + + // First do it w/verbose - baseline + buildCmd := exec.Command(dockerBinary, "build", "--no-cache", "-t", "verbose", ".") + buildCmd.Dir = ctx.Dir + out, _, err := runCommandWithOutput(buildCmd) + if err != nil { + t.Fatalf("failed to build the image w/o -q: %s, %v", out, err) + } + if !strings.Contains(out, "hi there") { + t.Fatalf("missing output:%s\n", out) + } + + // Now do it w/o verbose + buildCmd = exec.Command(dockerBinary, "build", "--no-cache", "-q", "-t", "verbose", ".") + buildCmd.Dir = ctx.Dir + out, _, err = runCommandWithOutput(buildCmd) + if err != nil { + t.Fatalf("failed to build the image w/ -q: %s, %v", out, err) + } + if strings.Contains(out, "hi there") { + t.Fatalf("Bad output, should not contain 'hi there':%s", out) + } + + logDone("build - not verbose") +}