diff --git a/packer/build.go b/packer/build.go index e697238a5..d16451118 100644 --- a/packer/build.go +++ b/packer/build.go @@ -6,6 +6,10 @@ import ( "sync" ) +// This is the key in configurations that is set to the name of the +// build. +const BuildNameConfigKey = "packer_build_name" + // This is the key in configurations that is set to "true" when Packer // debugging is enabled. const DebugConfigKey = "packer_debug" @@ -91,12 +95,13 @@ func (b *coreBuild) Prepare() (err error) { b.prepareCalled = true - debugConfig := map[string]interface{}{ + packerConfig := map[string]interface{}{ + BuildNameConfigKey: b.name, DebugConfigKey: b.debug, } // Prepare the builder - err = b.builder.Prepare(b.builderConfig, debugConfig) + err = b.builder.Prepare(b.builderConfig, packerConfig) if err != nil { log.Printf("Build '%s' prepare failure: %s\n", b.name, err) return @@ -106,7 +111,7 @@ func (b *coreBuild) Prepare() (err error) { for _, coreProv := range b.provisioners { configs := make([]interface{}, len(coreProv.config), len(coreProv.config)+1) copy(configs, coreProv.config) - configs = append(configs, debugConfig) + configs = append(configs, packerConfig) if err = coreProv.provisioner.Prepare(configs...); err != nil { return diff --git a/packer/build_test.go b/packer/build_test.go index 21a4b567b..576143727 100644 --- a/packer/build_test.go +++ b/packer/build_test.go @@ -39,19 +39,22 @@ func TestBuild_Name(t *testing.T) { func TestBuild_Prepare(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) - debugFalseConfig := map[string]interface{}{DebugConfigKey: false} + packerConfig := map[string]interface{}{ + BuildNameConfigKey: "test", + DebugConfigKey: false, + } build := testBuild() builder := build.builder.(*TestBuilder) build.Prepare() assert.True(builder.prepareCalled, "prepare should be called") - assert.Equal(builder.prepareConfig, []interface{}{42, debugFalseConfig}, "prepare config should be 42") + assert.Equal(builder.prepareConfig, []interface{}{42, packerConfig}, "prepare config should be 42") coreProv := build.provisioners[0] prov := coreProv.provisioner.(*TestProvisioner) assert.True(prov.prepCalled, "prepare should be called") - assert.Equal(prov.prepConfigs, []interface{}{42, debugFalseConfig}, "prepare should be called with proper config") + assert.Equal(prov.prepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config") corePP := build.postProcessors[0][0] pp := corePP.processor.(*TestPostProcessor) @@ -82,7 +85,10 @@ func TestBuild_Prepare_Twice(t *testing.T) { func TestBuild_Prepare_Debug(t *testing.T) { assert := asserts.NewTestingAsserts(t, true) - debugConfig := map[string]interface{}{DebugConfigKey: true} + packerConfig := map[string]interface{}{ + BuildNameConfigKey: "test", + DebugConfigKey: true, + } build := testBuild() builder := build.builder.(*TestBuilder) @@ -90,12 +96,12 @@ func TestBuild_Prepare_Debug(t *testing.T) { build.SetDebug(true) build.Prepare() assert.True(builder.prepareCalled, "prepare should be called") - assert.Equal(builder.prepareConfig, []interface{}{42, debugConfig}, "prepare config should be 42") + assert.Equal(builder.prepareConfig, []interface{}{42, packerConfig}, "prepare config should be 42") coreProv := build.provisioners[0] prov := coreProv.provisioner.(*TestProvisioner) assert.True(prov.prepCalled, "prepare should be called") - assert.Equal(prov.prepConfigs, []interface{}{42, debugConfig}, "prepare should be called with proper config") + assert.Equal(prov.prepConfigs, []interface{}{42, packerConfig}, "prepare should be called with proper config") } func TestBuild_Run(t *testing.T) {