Skip to content

Commit 6f14799

Browse files
Add scripts to DABs (#2813)
## Changes Scripts can be defined in a bundle YAML file as: ``` scripts: my_script: content: | echo "one" echo "two" ``` They can then be run by calling `databricks bundle run my_script` ## Why There are four primary benefits of having the scripts section in DABs: 1. Customers can scripts (like integration testing scripts) live and be versioned with their bundle. Since integration tests based on spark connect require authentication, scripts run via this mechanism will automatically have the appropriate authentication configured. 2. Simplifies setup for users who might not have their own build tools configured. 3. Allows us to stardarize documentation to always refer to the scripts section. 4. Make DABs in the workspace integration possible. Since DABs in the workspace cannot read arbitrary build file formats like Makefile. ### Why do we have an additional level of indentation with the `content` field? Why not inline it? The two main reasons are: 1. This mirrors what the artifacts block looks like. Users in the artifact block are able to specify which shell they want to run their build command in. We should offer the same functionality in the scripts section. 5. Leaves the room open for us to provide users with additional modifiers they might like to apply to their scripts. ## Tests Acceptance tests. --------- Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
1 parent 2f1627d commit 6f14799

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+920
-57
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Release v0.259.0
44

55
### Notable Changes
6+
* Add support for arbitrary scripts in DABs. Users can now define scripts in their bundle configuration. These scripts automatically inherit the bundle's credentials for authentication. They can be invoked with the `bundle run` command. ([#2813](https://github.com/databricks/cli/pull/2813))
67
* Error when the absolute path to `databricks.yml` contains a glob character. These are: `*`, `?`, `[`, `]` and `^`. If the path to the `databricks.yml` file on your local filesystem contains one of these characters, that could lead to incorrect computation of glob patterns for the `includes` block and might cause resources to be deleted. After this patch users will not be at risk for unexpected deletions due to this issue. ([#3096](https://github.com/databricks/cli/pull/3096))
78
* Diagnostics messages are no longer buffered to be printed at the end of command, flushed after every mutator ([#3175](https://github.com/databricks/cli/pull/3175))
89
* Diagnostics are now always rendered with forward slashes in file paths, even on Windows ([#3175](https://github.com/databricks/cli/pull/3175))

acceptance/bundle/debug/direct/out.stderr.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
10:07:59 Info: Phase: initialize pid=12345
2020
10:07:59 Debug: Apply pid=12345 mutator=validate:AllResourcesHaveValues
2121
10:07:59 Debug: Apply pid=12345 mutator=validate:interpolation_in_auth_config
22+
10:07:59 Debug: Apply pid=12345 mutator=validate:scripts
2223
10:07:59 Debug: Apply pid=12345 mutator=RewriteSyncPaths
2324
10:07:59 Debug: Apply pid=12345 mutator=SyncDefaultPath
2425
10:07:59 Debug: Apply pid=12345 mutator=SyncInferRoot

acceptance/bundle/debug/direct/output.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Validation OK!
1414
+>>> [CLI] bundle validate --debug
1515
10:07:59 Info: start pid=12345 version=[DEV_VERSION] args="[CLI], bundle, validate, --debug"
1616
10:07:59 Debug: Found bundle root at [TEST_TMP_DIR] (file [TEST_TMP_DIR]/databricks.yml) pid=12345
17-
@@ -59,8 +61,4 @@
17+
@@ -60,8 +62,4 @@
1818
10:07:59 Debug: Apply pid=12345 mutator=metadata.AnnotateJobs
1919
10:07:59 Debug: Apply pid=12345 mutator=metadata.AnnotatePipelines
2020
-10:07:59 Debug: Apply pid=12345 mutator=terraform.Initialize

acceptance/bundle/debug/tf/out.stderr.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
10:07:59 Info: Phase: initialize pid=12345
1818
10:07:59 Debug: Apply pid=12345 mutator=validate:AllResourcesHaveValues
1919
10:07:59 Debug: Apply pid=12345 mutator=validate:interpolation_in_auth_config
20+
10:07:59 Debug: Apply pid=12345 mutator=validate:scripts
2021
10:07:59 Debug: Apply pid=12345 mutator=RewriteSyncPaths
2122
10:07:59 Debug: Apply pid=12345 mutator=SyncDefaultPath
2223
10:07:59 Debug: Apply pid=12345 mutator=SyncInferRoot

acceptance/bundle/run/inline-script/cwd/script

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ trace cd a/b/c
22

33
trace python3 -c 'import os; print(os.getcwd())'
44

5-
# Scripts that bundle run executes should run from the bundle root.
5+
# Scripts that bundle run executes inline should run from the current working directory.
66
trace $CLI bundle run -- python3 -c 'import os; print(os.getcwd())'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
scripts:
2+
foo:
3+
content: |
4+
echo 'hello'
5+
6+
me:
7+
content: $CLI current-user me
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Local = true
2+
Cloud = false
3+
4+
[EnvMatrix]
5+
DATABRICKS_CLI_DEPLOYMENT = ["terraform", "direct-exp"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
>>> [CLI] bundle run foo
3+
hello
4+
5+
>>> [CLI] bundle run me
6+
{
7+
"id":"[USERID]",
8+
"userName":"[USERNAME]"
9+
}
10+
11+
>>> [CLI] bundle run foo arg1 arg2
12+
Error: additional arguments are not supported for scripts. Got: [arg1 arg2]. We recommend using environment variables to pass runtime arguments to a script. For example: FOO=bar databricks bundle run my_script.
13+
14+
Exit code: 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trace $CLI bundle run foo
2+
3+
trace $CLI bundle run me
4+
5+
errcode trace $CLI bundle run foo arg1 arg2

acceptance/bundle/run/scripts/cwd/a/b/c/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)