diff --git a/packer.go b/packer.go index 317731f09..d645df45e 100644 --- a/packer.go +++ b/packer.go @@ -133,6 +133,13 @@ func wrappedMain() int { envConfig.Ui = &packer.MachineReadableUi{ Writer: os.Stdout, } + + // Set this so that we don't get colored output in our machine- + // readable UI. + if err := os.Setenv("PACKER_NO_COLOR", "1"); err != nil { + fmt.Fprintf(os.Stderr, "Packer failed to initialize UI: %s\n", err) + return 1 + } } env, err := packer.NewEnvironment(envConfig) diff --git a/packer/ui.go b/packer/ui.go index e0a4685ce..0826c5abc 100644 --- a/packer/ui.go +++ b/packer/ui.go @@ -110,6 +110,11 @@ func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string { } func (u *ColoredUi) supportsColors() bool { + // Never use colors if we have this environmental variable + if os.Getenv("PACKER_NO_COLOR") != "" { + return false + } + // For now, on non-Windows machine, just assume it does if runtime.GOOS != "windows" { return true