-
Notifications
You must be signed in to change notification settings - Fork 195
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
base: main
Are you sure you want to change the base?
Changes from all commits
8044e34
64bb5c1
240d6ba
46a34af
File filter
Filter by extension
Conversations
Jump to
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
|
|
||
| >>> [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 | ||
|
|
||
| Exit code: 1 | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1 @@ | ||||||
| errcode trace $CLI bundle validate | ||||||
|
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.
Suggested change
|
||||||
| 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.
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1971,6 +1971,9 @@ scripts: | |
| "content": | ||
| "description": |- | ||
| PLACEHOLDER | ||
| "env": | ||
| "description": |- | ||
| PLACEHOLDER | ||
|
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. please add a description here so it shows up in tooltips via the jsonschema |
||
| sync: | ||
| "description": |- | ||
| The files and file paths to include or exclude in the bundle. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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 |
||
| 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.