Sub topic 7
Validating, deploying, and running a bundle
This chapter covers the three commands you will run most often: databricks bundle validate, databricks bundle deploy, and databricks bundle run. It assumes you have the Databricks CLI installed and authenticated, and that you have a databricks.yml with at least one job and a dev target, like the one built in the earlier chapters. You should also be comfortable reading YAML and running shell commands.
The loop at a glance
Validate checks your configuration locally. Deploy copies files to the workspace and creates or updates resources. Run starts a deployed job or pipeline. Each step builds on the one before it, so you normally run them in that order.
Selecting a target
All three commands act on one target. Pass it with -t (or --target). If you omit it, the CLI uses the target marked default: true. If the bundle has only one target, the CLI uses that one. In a bundle with several targets and no default, leaving out -t is an error. In scripts, always pass -t explicitly so a change to the default can't redirect a deployment.
Validating
databricks bundle validate -t devValidation loads databricks.yml, merges every file matched by include, applies the chosen target's overrides, and resolves variables and substitutions such as ${var.catalog} and ${bundle.target}. It then checks the result against the bundle schema. On success it prints a summary of the bundle: its name, target, workspace host, and the resolved paths.
Validation needs working authentication. Some values, such as ${workspace.current_user.userName}, can only be resolved by asking the workspace. A validate failure with an authentication message therefore usually points to your profile, not your YAML.
To see exactly what the CLI will deploy, print the fully resolved configuration as JSON:
databricks bundle validate -t prod -o jsonThis is the fastest way to debug a target override, because it shows the merged result. You can see which node_type_id ended up in the job cluster, or which run_as applies in prod.
You can also supply or override variables at validation time:
databricks bundle validate -t prod --var="catalog=prod_catalog"Variable values come from several places. In decreasing priority:
- The
--varflag. - An environment variable named
BUNDLE_VAR_<name>, for exampleBUNDLE_VAR_catalog. - The target's
variablesblock. - The variable's
default.
A variable that appears in none of these, such as node_type_id in a target that doesn't set it, produces a "no value assigned" error.
Deploying
databricks bundle deploy -t devDeploy does the following:
- Runs validation first.
- Builds any configured artifacts, such as wheels (covered in a later chapter).
- Uploads the bundle's files to the workspace under the target's
root_path. - Compares your configuration with the recorded deployment state.
- Creates, updates, or deletes resources so the workspace matches your configuration.
Where things land
If a target doesn't set workspace.root_path, the bundle goes under your user folder at ~/.bundle/<bundle name>/<target>. Under that path the CLI creates three subfolders:
| Subfolder | Contents |
|---|---|
| `files` | Your synchronized source files, such as notebooks and Python modules |
| `artifacts` | Built outputs, such as wheel files |
| `state` | Records of what the bundle has deployed |
The prod target in the spine sets an explicit root_path under /Workspace/Shared/.bundle/. A shared location keeps a production deployment from depending on one person's home folder.
What development mode changes
A target with mode: development is built for iteration. During deploy, the CLI prefixes resource names with [dev <your username>], tags jobs with dev, and pauses schedules and triggers. Two developers can then deploy the same bundle to the same workspace without overwriting each other's jobs, and nobody gets an unexpected scheduled run.
A target with mode: production does the opposite. It doesn't rename resources, and it applies extra checks. These include warnings or errors when run_as or a stable root_path is missing. Treat production mode as a prompt to configure identity and location deliberately.
Idempotence and the lock
Deploy is idempotent. Running it twice with no changes does nothing the second time. If you rename a job in YAML, the bundle updates the existing job. If you remove a job from YAML, the next deploy deletes it from the workspace, because the recorded state says the bundle created it. The CLI asks you to confirm destructive changes, which matters in a terminal. In automation you must opt in with --auto-approve.
During a deploy, the CLI holds a lock in the workspace so two deployments don't write state at the same time. If a deploy is interrupted and leaves the lock behind, you can override it with --force-lock. Use this only when you are sure no other deployment is running.
Other useful flags:
--var="name=value"sets a variable for this invocation.--fail-on-active-runsstops the deploy if a job or pipeline in the bundle is running, instead of changing it mid-run.--auto-approveskips confirmation prompts for destructive changes.
Running
Deploying a job doesn't start it. To start it, pass the resource key, which is the YAML key under resources.jobs, not the job's display name:
databricks bundle run -t dev daily_etlIn the spine's example the key is daily_etl, and the name happens to match. In a development deployment the workspace job is named [dev <you>] daily_etl, so the two differ. The CLI looks up the job through the bundle's state, so you use the key.
By default run waits for completion. It prints a link to the run and its status as it progresses, and it exits with a non-zero code if the run fails. That exit code is what lets a CI step fail when a job fails.
To start a run and return immediately, use --no-wait:
databricks bundle run -t dev daily_etl --no-waitIf you omit the key, the CLI lists the runnable resources in the bundle and asks you to choose. Pipelines can be run the same way, and they accept options such as --full-refresh for a full refresh of selected tables or --refresh-all.
run uses what is deployed, not what is on your disk. If you edit src/ingest.py and run without deploying, the old version executes. Always deploy before you run.
Inspecting the deployment
To see what a target currently has deployed, use:
databricks bundle summary -t devIt lists each resource with its workspace ID and a URL. This is useful for finding the job a bundle created, particularly after the [dev <you>] prefix has been applied.
A complete working session
This sequence takes a change from edit to verified run:
# 1. Check the merged configuration and variable values
databricks bundle validate -t dev -o json
# 2. Push files and resource changes
databricks bundle deploy -t dev
# 3. Run the job and wait for the result
databricks bundle run -t dev daily_etl
# 4. Look up the deployed resources and their URLs
databricks bundle summary -t devCommon errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Authentication error during `validate` | Missing or expired profile for the target's host | Run `databricks auth login --host <url>` again, then retry |
| "no value assigned to required variable" | A variable has no default and the target doesn't set it | Add a target override, pass `--var`, or set `BUNDLE_VAR_<name>` |
| Unknown field or schema warning | Typo or wrong nesting in YAML | Compare against the `-o json` output to see where the value ended up |
| Notebook path not found at run time | `notebook_path` is relative to the YAML file that defines the job, not to the bundle root | In `resources/daily_etl.yml`, use `../src/ingest.py` |
| Deploy fails on a lock | A previous deployment was interrupted, or another is running | Confirm nothing is running, then use `--force-lock` |
| `run` shows old behavior | Local edits were never deployed | Run `deploy` again before `run` |
| Cluster creation fails | Node type is unavailable in your cloud or region | Set a valid `node_type_id` for the target |
Exercise
You change the catalog variable's dev value in databricks.yml, then run databricks bundle run -t dev daily_etl without deploying. Which catalog does the job use, and why? What two commands should you run to check the change and apply it?
Show answer
The job uses the old catalog. run starts the job as it was last deployed, and the new value exists only in your local files. Run databricks bundle validate -t dev -o json to confirm the new value appears in the resolved configuration. Then run databricks bundle deploy -t dev to update the job, and run it again.
Exercise
A CI step runs databricks bundle deploy -t prod and hangs after you removed a job from the YAML. What is the likely cause, and how do you fix it in an unattended pipeline?
Show answer
Removing the job means the deploy must delete it from the workspace, which is a destructive change, so the CLI waits for confirmation that nobody can give in CI. Pass --auto-approve so the deploy proceeds without a prompt. Only do this after reviewing the change, for example in a pull request.