Skip to content

Add env section to bundle scripts for DABs interpolation#5299

Open
shreyas-goenka wants to merge 6 commits into
mainfrom
script-env-section
Open

Add env section to bundle scripts for DABs interpolation#5299
shreyas-goenka wants to merge 6 commits into
mainfrom
script-env-section

Conversation

@shreyas-goenka

@shreyas-goenka shreyas-goenka commented May 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #4179.

Adds an env: map to scripts.<name>. Values may reference ${bundle.*}, ${workspace.*}, and ${var.*}; they're resolved before the script runs and exported into its shell, where content uses plain $NAME:

scripts:
  show_env:
    env:
      REGION: ${var.region}
    content: echo "region=$REGION"

content is still passed to the shell as-is, so ${...} in content stays unsupported (the error now points to the env: section). Env values with any other prefix (e.g. ${resources.*}) are rejected. On a name collision with the CLI-injected auth vars, the script's env: wins.

This pull request was AI-assisted by Isaac.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Integration test report

Commit: a32d68c

Run: 29084501634

Env 🔄​flaky 💚​RECOVERED 🙈​SKIP ✅​pass 🙈​skip Time
💚​ aws linux 4 4 230 1080 4:59
💚​ aws windows 4 4 232 1078 7:06
💚​ aws-ucws linux 4 4 314 998 5:31
💚​ aws-ucws windows 4 4 316 996 7:22
💚​ azure linux 4 4 230 1079 4:51
💚​ azure windows 4 4 232 1077 7:01
💚​ azure-ucws linux 4 4 316 995 5:31
🔄​ azure-ucws windows 1 4 4 317 993 7:56
💚​ gcp linux 4 4 229 1081 5:17
💚​ gcp windows 4 4 231 1079 7:09
9 interesting tests: 4 RECOVERED, 4 SKIP, 1 flaky
Test Name aws linux aws windows aws-ucws linux aws-ucws windows azure linux azure windows azure-ucws linux azure-ucws windows gcp linux gcp windows
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
🙈​ TestAccept/bundle/invariant/no_drift 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_endpoints/drift/recreated_same_name 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/bundle/resources/vector_search_indexes/recreate/embedding_dimension 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🙈​ TestAccept/ssh/connection 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S 🙈​S
🔄​ TestSyncIncrementalFileOverwritesFolder ✅​p ✅​p ✅​p ✅​p ✅​p ✅​p ✅​p 🔄​f ✅​p ✅​p
💚​ TestFetchRepositoryInfoAPI_FromRepo 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
💚​ TestFetchRepositoryInfoAPI_FromRepo/root 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
💚​ TestFetchRepositoryInfoAPI_FromRepo/subdir 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 10 slowest tests (at least 2 minutes):
duration env testname
6:31 azure-ucws windows TestAccept
6:18 aws-ucws windows TestAccept
6:11 aws windows TestAccept
6:09 gcp windows TestAccept
6:03 azure windows TestAccept
2:56 azure linux TestAccept
2:55 aws linux TestAccept
2:54 gcp linux TestAccept
2:50 azure-ucws linux TestAccept
2:47 aws-ucws linux TestAccept

@shreyas-goenka shreyas-goenka force-pushed the script-env-section branch 5 times, most recently from f373d61 to b68897d Compare June 29, 2026 16:37
scripts.<name> now accepts an env: map whose values may reference
${bundle.*}, ${workspace.*}, and ${var.*}. The script content is still
passed to the shell as-is (no DABs interpolation), removing the ambiguity
between bundle variables and shell variables that previously forced all
${...} usage to be rejected.

When an env value references an unsupported prefix (e.g. ${resources.*}),
validation reports a clear error pointing at the field. The content-side
error now suggests the new env section instead of just stating ${...} is
unsupported.

Fixes #4179

Co-authored-by: Isaac
@shreyas-goenka shreyas-goenka marked this pull request as ready for review July 6, 2026 13:30
Resolved conflicts in NEXT_CHANGELOG.md (kept both entry sets) and
bundle/internal/schema/annotations.yml (took main's regenerated layout,
re-added the scripts env field annotation).

Co-authored-by: Isaac
Comment thread acceptance/bundle/run/scripts/env-bad-prefix/output.txt
Comment thread NEXT_CHANGELOG.md
Fix the earlier bad merge in NEXT_CHANGELOG.md: the prior merge
resurrected Bundles entries that had already been swept into the
v1.6.0 release. Reset the changelog to origin/main and re-added only
the scripts env entry.

Co-authored-by: Isaac
Comment thread bundle/internal/schema/annotations.yml Outdated
PLACEHOLDER
"env":
"description": |-
PLACEHOLDER

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — added a description for scripts.<name>.env in annotations.yml (regenerated jsonschema.json).

Comment thread cmd/bundle/run.go
Comment on lines +281 to +286
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])
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an acceptance test for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the env-precedence acceptance test: a script's env: entry sets DATABRICKS_BUNDLE_TARGET=from-script-env and the output confirms it wins over the CLI-injected value.

@@ -0,0 +1 @@
errcode trace $CLI bundle validate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errcode trace $CLI bundle validate
musterr trace $CLI bundle validate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied musterr (dropped the redundant errcode).

- Add a real description for scripts.<name>.env in annotations.yml so it
  surfaces in jsonschema tooltips (regenerated jsonschema.json).
- Use musterr instead of errcode in the env-bad-prefix script to assert
  the command must fail.
- Add an env-precedence acceptance test proving a script's env: entry
  overrides a CLI-injected variable (DATABRICKS_BUNDLE_TARGET).

Co-authored-by: Isaac
v1.8.0 was cut, emptying the Bundles section of NEXT_CHANGELOG.md on
main. Kept only the scripts env entry.

Co-authored-by: Isaac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature suggestion - variable interpolation in DAB script

4 participants