Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 213
Add env section to bundle scripts for DABs interpolation#5299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
8044e3464bb5c1240d6ba46a34af7b31901a32d68cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| bundle: | ||
| name: script-env-bad-prefix | ||
| resources: | ||
| jobs: | ||
| my_job: | ||
| name: my-job | ||
| scripts: | ||
| bad: | ||
| env: | ||
| JOB_ID: ${resources.jobs.my_job.id} | ||
| UNKNOWN: ${something.else} | ||
| content: echo "$JOB_ID $UNKNOWN" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| >>> [CLI] bundle validate | ||
| Error: ${resources.jobs.my_job.id} cannot be used in scripts.bad.env.JOB_ID; only ${bundle.*}, ${workspace.*}, and ${var.*} are resolved before scripts execute | ||
| at scripts.bad.env.JOB_ID | ||
| in databricks.yml:12:15 | ||
| Error: ${something.else} cannot be used in scripts.bad.env.UNKNOWN; only ${bundle.*}, ${workspace.*}, and ${var.*} are resolved before scripts execute | ||
| at scripts.bad.env.UNKNOWN | ||
| in databricks.yml:13:16 | ||
| Name: script-env-bad-prefix | ||
| Target: default | ||
| Found 2 errors | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| musterr trace $CLI bundle validate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Local = true | ||
| Cloud = false | ||
| [EnvMatrix] | ||
| DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| bundle: | ||
| name: script-env-precedence | ||
| targets: | ||
| default: | ||
| default: true | ||
| # A script's env: entry must win over the DATABRICKS_BUNDLE_TARGET variable the | ||
| # CLI injects into the script process (executeScript appends env: last). | ||
| scripts: | ||
| show_target: | ||
| env: | ||
| DATABRICKS_BUNDLE_TARGET: from-script-env | ||
| content: echo "target=$DATABRICKS_BUNDLE_TARGET" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| >>> [CLI] bundle run show_target | ||
| target=from-script-env |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| trace $CLI bundle run show_target |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Local = true | ||
| Cloud = false | ||
| [EnvMatrix] | ||
| DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| bundle: | ||
| name: script-env-section | ||
| variables: | ||
| region: | ||
| default: us-west-2 | ||
| database: | ||
| default: mydb | ||
| scripts: | ||
| show_env: | ||
| env: | ||
| BUNDLE_NAME: ${bundle.name} | ||
| REGION: ${var.region} | ||
| DATABASE: ${var.database} | ||
| MIXED: "region=${var.region};db=${var.database}" | ||
| content: |- | ||
| echo "bundle=$BUNDLE_NAME" | ||
| echo "region=$REGION" | ||
| echo "database=$DATABASE" | ||
| echo "mixed=$MIXED" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| >>> [CLI] bundle run show_env | ||
| bundle=script-env-section | ||
| region=us-west-2 | ||
| database=mydb | ||
| mixed=region=us-west-2;db=mydb |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| trace $CLI bundle run show_env |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Local = true | ||
| Cloud = false | ||
| [EnvMatrix] | ||
| DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,64 @@ | ||
| >>> [CLI] bundle deploy | ||
| Error: Found ${FOO} in script one. Interpolation syntax ${...} is not allowed in scripts | ||
| Error: Found ${FOO} in script one.content. Interpolation syntax ${...} is not supported in script content | ||
| at scripts.one.content | ||
| in databricks.yml:6:14 | ||
| We do not support the ${...} interpolation syntax in scripts because | ||
| it's ambiguous whether it's a variable reference or reference to an | ||
| environment variable. | ||
| The ${...} syntax is not allowed in script content. To use a bundle value, | ||
| declare an environment variable in the script's "env:" section and reference it | ||
| from "content" with $NAME: | ||
| Error: Found ${var.BAR} in script two. Interpolation syntax ${...} is not allowed in scripts | ||
| scripts: | ||
| one: | ||
| env: | ||
| MY_VAR: ${var.foo} | ||
| content: echo "$MY_VAR" | ||
| Error: Found ${var.BAR} in script two.content. Interpolation syntax ${...} is not supported in script content | ||
| at scripts.two.content | ||
| in databricks.yml:8:14 | ||
| We do not support the ${...} interpolation syntax in scripts because | ||
| it's ambiguous whether it's a variable reference or reference to an | ||
| environment variable. | ||
| The ${...} syntax is not allowed in script content. To use a bundle value, | ||
| declare an environment variable in the script's "env:" section and reference it | ||
| from "content" with $NAME: | ||
| scripts: | ||
| two: | ||
| env: | ||
| MY_VAR: ${var.foo} | ||
| content: echo "$MY_VAR" | ||
| Exit code: 1 | ||
| >>> [CLI] bundle run foo | ||
| Error: Found ${FOO} in script one. Interpolation syntax ${...} is not allowed in scripts | ||
| Error: Found ${FOO} in script one.content. Interpolation syntax ${...} is not supported in script content | ||
| at scripts.one.content | ||
| in databricks.yml:6:14 | ||
| We do not support the ${...} interpolation syntax in scripts because | ||
| it's ambiguous whether it's a variable reference or reference to an | ||
| environment variable. | ||
| The ${...} syntax is not allowed in script content. To use a bundle value, | ||
| declare an environment variable in the script's "env:" section and reference it | ||
| from "content" with $NAME: | ||
| Error: Found ${var.BAR} in script two. Interpolation syntax ${...} is not allowed in scripts | ||
| scripts: | ||
| one: | ||
| env: | ||
| MY_VAR: ${var.foo} | ||
| content: echo "$MY_VAR" | ||
| Error: Found ${var.BAR} in script two.content. Interpolation syntax ${...} is not supported in script content | ||
| at scripts.two.content | ||
| in databricks.yml:8:14 | ||
| We do not support the ${...} interpolation syntax in scripts because | ||
| it's ambiguous whether it's a variable reference or reference to an | ||
| environment variable. | ||
| The ${...} syntax is not allowed in script content. To use a bundle value, | ||
| declare an environment variable in the script's "env:" section and reference it | ||
| from "content" with $NAME: | ||
| scripts: | ||
| two: | ||
| env: | ||
| MY_VAR: ${var.foo} | ||
| content: echo "$MY_VAR" | ||
| Exit code: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,7 @@ import ( | ||
| "slices" | ||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/config" | ||
| "github.com/databricks/cli/bundle/env" | ||
| "github.com/databricks/cli/bundle/resources" | ||
| "github.com/databricks/cli/bundle/run" | ||
| @@ -165,7 +166,7 @@ Example usage: | ||
| if len(runArgs) > 0 { | ||
| return fmt.Errorf("additional arguments are not supported for scripts. Got: %v. We recommend using environment variables to pass runtime arguments to a script. For example: FOO=bar databricks bundle run my_script", runArgs) | ||
| } | ||
| return executeScript(b.Config.Scripts[key].Content, cmd, b) | ||
| return executeScript(b.Config.Scripts[key], cmd, b) | ||
| } | ||
| return nil | ||
| @@ -276,8 +277,14 @@ func scriptEnv(cmd *cobra.Command, b *bundle.Bundle) []string { | ||
| return out | ||
| } | ||
| func executeScript(content string, cmd *cobra.Command, b *bundle.Bundle) error { | ||
| return execv.Shell(content, b.BundleRootPath, scriptEnv(cmd, b)) | ||
| func executeScript(script config.Script, cmd *cobra.Command, b *bundle.Bundle) error { | ||
| env := scriptEnv(cmd, b) | ||
| // Append after the auth/target variables so a script's env: section takes | ||
| // precedence on collision (os/exec uses the last value for a duplicate key). | ||
| for _, name := range slices.Sorted(maps.Keys(script.Env)) { | ||
| env = append(env, name+"="+script.Env[name]) | ||
| } | ||
Comment on lines
+281
to
+286
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an acceptance test for this ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the | ||
| return execv.Shell(script.Content, b.BundleRootPath, env) | ||
| } | ||
| func executeInline(cmd *cobra.Command, args []string, b *bundle.Bundle) error { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.