diff --git a/acceptance/bundle/exec/databricks-cli/basic/databricks.yml b/acceptance/bundle/exec/databricks-cli/target-is-passed/databricks.yml similarity index 100% rename from acceptance/bundle/exec/databricks-cli/basic/databricks.yml rename to acceptance/bundle/exec/databricks-cli/target-is-passed/databricks.yml diff --git a/acceptance/bundle/exec/databricks-cli/basic/out.requests.txt b/acceptance/bundle/exec/databricks-cli/target-is-passed/out.requests.txt similarity index 100% rename from acceptance/bundle/exec/databricks-cli/basic/out.requests.txt rename to acceptance/bundle/exec/databricks-cli/target-is-passed/out.requests.txt diff --git a/acceptance/bundle/exec/databricks-cli/basic/output.txt b/acceptance/bundle/exec/databricks-cli/target-is-passed/output.txt similarity index 100% rename from acceptance/bundle/exec/databricks-cli/basic/output.txt rename to acceptance/bundle/exec/databricks-cli/target-is-passed/output.txt diff --git a/acceptance/bundle/exec/databricks-cli/basic/script b/acceptance/bundle/exec/databricks-cli/target-is-passed/script similarity index 100% rename from acceptance/bundle/exec/databricks-cli/basic/script rename to acceptance/bundle/exec/databricks-cli/target-is-passed/script diff --git a/bundle/config/mutator/default_target.go b/bundle/config/mutator/default_target.go index 73d99002a..781c075ec 100644 --- a/bundle/config/mutator/default_target.go +++ b/bundle/config/mutator/default_target.go @@ -13,11 +13,13 @@ type defineDefaultTarget struct { name string } +const DefaultTargetName = "default" + // DefineDefaultTarget adds a target named "default" // to the configuration if none have been defined. func DefineDefaultTarget() bundle.Mutator { return &defineDefaultTarget{ - name: "default", + name: DefaultTargetName, } } diff --git a/cmd/bundle/exec.go b/cmd/bundle/exec.go index b5a52f609..acf914f59 100644 --- a/cmd/bundle/exec.go +++ b/cmd/bundle/exec.go @@ -7,6 +7,7 @@ import ( "strings" "sync" + "github.com/databricks/cli/bundle/config/mutator" "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/auth" "github.com/spf13/cobra" @@ -63,19 +64,24 @@ Examples: childCmd := exec.Command(args[0], args[1:]...) env := auth.ProcessEnv(root.ConfigUsed(cmd.Context())) - // TODO: Test that this works correctly for all permutations. - // TODO: Do the same for profile flag. - // TODO: TODO: What happens here if a default target is resolved? When - // no targets are defined? - env = append(env, "DATABRICKS_BUNDLE_TARGET="+b.Config.Bundle.Target) + + // If user has specified a target, pass it to the child command. If the + // target is the default target, we don't need to pass it explicitly since + // the CLI will use the default target by default. + // This is only useful for when the Databricks CLI is the child command. + if b.Config.Bundle.Target != mutator.DefaultTargetName { + env = append(env, "DATABRICKS_BUNDLE_TARGET="+b.Config.Bundle.Target) + } // If the bundle has a profile, explicitly pass it to the child command. // This is unnecessary for tools that follow the unified authentication spec. // However, because the CLI can read the profile from the bundle itself, we // need to pass it explicitly. + // This is only useful for when the Databricks CLI is the child command. if b.Config.Workspace.Profile != "" { env = append(env, "DATABRICKS_CONFIG_PROFILE="+b.Config.Workspace.Profile) } + childCmd.Env = env // Execute all scripts from the bundle root directory. This behavior can