Skip to content

Commit 47948b7

Browse files
Add inline script execution support to bundle run (#2413)
## Changes This PR adds the ability to execute scripts inline using the `databricks bundle run` command. This allows users to execute commands with the same authentication credentials as the bundle is configured to use.. Note: The auth credentials are passed to child processes via environment variables. ## Why Configuring downstream tools like DBConnect to use the same authentication credentials as your bundle can be challenging. Having this command allows users to directly run `databricks bundle run -t foo -- uv run pytest` (or equivalent) to directly run integration tests against the configured target without having to worry about how to pass authentication credentials to DBConnect. ## Tests Acceptance tests.
1 parent bf6858d commit 47948b7

File tree

39 files changed

+501
-2
lines changed

39 files changed

+501
-2
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.250.0
44

55
### Notable Changes
6+
* Added inline script execution support to bundle run. You can now run scripts in the same authentication context as a DAB using the databricks bundle run command. ([#2413](https://github.com/databricks/cli/pull/2413))
67

78
### Dependency updates
89

acceptance/bundle/help/bundle-run/output.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,23 @@ parameter names.
1919
If the specified job does not use job parameters and the job has a Python file
2020
task or a Python wheel task, the second example applies.
2121

22+
---------------------------------------------------------
23+
24+
You can also use the bundle run command to execute scripts / commands in the same
25+
authentication context as the bundle.
26+
27+
Authentication to the input command will be provided by setting the appropriate
28+
environment variables that Databricks tools use to authenticate.
29+
30+
Example usage:
31+
1. databricks bundle run -- echo "hello, world"
32+
2. databricks bundle run -- /bin/bash -c "echo hello"
33+
3. databricks bundle run -- uv run pytest
34+
35+
---------------------------------------------------------
36+
2237
Usage:
23-
databricks bundle run [flags] KEY
38+
databricks bundle run [flags] [KEY]
2439

2540
Job Flags:
2641
--params stringToString comma separated k=v pairs for job parameters (default [])
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
name: foobar
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
>>> [CLI] bundle run -- echo hello, world
3+
hello, world
4+
5+
>>> [CLI] bundle run -- --help
6+
Error: looking up "--help" failed: exec: "--help": executable file not found in PATH
7+
8+
Exit code: 1
9+
10+
>>> [CLI] bundle run -- bash -c exit 5
11+
12+
Exit code: 5
13+
14+
>>> cat stderr.txt
15+
Hello
16+
17+
>>> cat -
18+
abc
19+
20+
>>> [CLI] bundle run -- printf hello
21+
hello<EOL>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
trace $CLI bundle run -- echo "hello, world"
2+
3+
# The CLI should not parse the --help flag and should try to run it as an executable
4+
# instead.
5+
errcode trace $CLI bundle run -- --help
6+
7+
# The error message should include the exit code.
8+
errcode trace $CLI bundle run -- bash -c "exit 5"
9+
10+
# stderr should also be passed through.
11+
$CLI bundle run -- python3 -c "import sys; print('Hello', file=sys.stderr)" 2> stderr.txt
12+
trace cat stderr.txt
13+
rm stderr.txt
14+
15+
# stdin should be passed through
16+
echo "abc" > abc.txt
17+
trace cat - < abc.txt
18+
rm abc.txt
19+
20+
# no newline
21+
trace $CLI bundle run -- printf "hello"
22+
23+
# print newline to comply with whitespace linter
24+
printf "<EOL>\n"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[[Repls]]
2+
Old = "\\$PATH"
3+
New = "PATH"
4+
5+
[[Repls]]
6+
Old = "%PATH%"
7+
New = "PATH"

acceptance/bundle/run/inline-script/cwd/a/b/c/.gitkeep

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bundle:
2+
name: foobar
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
>>> cd a/b/c
3+
4+
>>> python3 -c import os; print(os.getcwd())
5+
[TEST_TMP_DIR]/a/b/c
6+
7+
>>> [CLI] bundle run -- python3 -c import os; print(os.getcwd())
8+
[TEST_TMP_DIR]/a/b/c
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trace cd a/b/c
2+
3+
trace python3 -c 'import os; print(os.getcwd())'
4+
5+
# Scripts that bundle run executes should run from the bundle root.
6+
trace $CLI bundle run -- python3 -c 'import os; print(os.getcwd())'

0 commit comments

Comments
 (0)