From f7bd4031517905c1aededff95e9d0a53002f3f72 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Aug 2013 09:59:56 -0700 Subject: [PATCH] command/build: machine-readable artifacts --- command/build/command.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/command/build/command.go b/command/build/command.go index b52f906a1..da7f62d81 100644 --- a/command/build/command.go +++ b/command/build/command.go @@ -9,6 +9,7 @@ import ( "log" "os" "os/signal" + "strconv" "strings" "sync" ) @@ -195,7 +196,16 @@ func (c Command) Run(env packer.Environment, args []string) int { if len(artifacts) > 0 { env.Ui().Say("\n==> Builds finished. The artifacts of successful builds are:") for name, buildArtifacts := range artifacts { - for _, artifact := range buildArtifacts { + // Create a UI for the machine readable stuff to be targetted + ui := &packer.TargettedUi{ + Target: name, + Ui: env.Ui(), + } + + // Machine-readable helpful + ui.Machine("artifact-count", strconv.FormatInt(int64(len(buildArtifacts)), 10)) + + for i, artifact := range buildArtifacts { var message bytes.Buffer fmt.Fprintf(&message, "--> %s: ", name) @@ -205,6 +215,24 @@ func (c Command) Run(env packer.Environment, args []string) int { fmt.Fprint(&message, "") } + iStr := strconv.FormatInt(int64(i), 10) + if artifact != nil { + ui.Machine("artifact", iStr, "builder-id", artifact.BuilderId()) + ui.Machine("artifact", iStr, "id", artifact.Id()) + ui.Machine("artifact", iStr, "string", message.String()) + + files := artifact.Files() + ui.Machine("artifact", + iStr, + "files-count", strconv.FormatInt(int64(len(files)), 10)) + for fi, file := range files { + fiStr := strconv.FormatInt(int64(fi), 10) + ui.Machine("artifact", iStr, "file", fiStr, file) + } + } else { + ui.Machine("artifact", iStr, "nil") + } + env.Ui().Say(message.String()) } }