Sub topic 7
Validating, deploying, and running a bundle
This chapter covers the three commands you use most: validate, deploy, and run. It assumes you have the Databricks CLI installed and authenticated, and that you have a databricks.yml with a job resource, as in the earlier chapters. It also assumes you know basic YAML and Git.
The working model
A bundle is configuration, and nothing exists in the workspace until you deploy it. The CLI reads databricks.yml and the included resource files. It merges in the settings for the target you chose, and it resolves variables. Then it uploads files and creates or updates resources through the Databricks APIs.
Every command takes a target with -t. If you omit it, the CLI uses the target marked default: true.
Validate
validate checks the configuration before anything changes in the workspace. It catches YAML mistakes, unknown fields, and missing variable values.
databricks bundle validate -t devOn success it prints a summary of the bundle name, target, and workspace. To see the fully merged configuration for a target, add -o json. This is the quickest way to confirm that a target override or ${var.catalog} resolved the way you expected.
databricks bundle validate -t prod -o jsonDeploy
deploy uploads your local files to the workspace and creates or updates the resources.
databricks bundle deploy -t devIn a mode: development target, the CLI prefixes resource names with [dev <your-username>] and pauses schedules. Two developers can therefore deploy the same bundle without overwriting each other. In a mode: production target, names stay as written. The bundle files go under the root_path you configured, and the CLI records state there so that later deploys know what already exists.
Deploy is repeatable. If nothing changed, it changes nothing. If you edit a job's cluster size, it updates the existing job instead of creating a second one.
You can override a variable for a single invocation:
databricks bundle deploy -t prod --var="catalog=prod_catalog"Run
run starts a deployed resource. You name it by its key in the resources section, which for the earlier example is daily_etl.
databricks bundle run -t dev daily_etlThe command waits for the run to finish and streams its status. It runs what you last deployed, not your local files. If you changed a notebook, deploy again first.
A frequent mistake is to run without deploying, or to deploy one target and run another. Always use the same -t value for both commands.
A typical loop
- Edit the YAML or the notebook.
- Run
databricks bundle validate -t dev. - Run
databricks bundle deploy -t dev. - Run
databricks bundle run -t dev daily_etl. - Check the run output in the workspace, then repeat.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `variable node_type_id is not defined` or a missing value | A variable has no default and the target gives no value | Add a value under `targets.<name>.variables`, or pass `--var` |
| Authentication or `401` error | The profile is expired or points at another workspace | Run `databricks auth login --host <url>` again |
| Notebook not found | `notebook_path` is wrong relative to the resource file | Paths are relative to the YAML file that declares them, so check the `../` |
| The job ran old code | You ran without deploying first | Deploy, then run |
| Unknown field warning | Typo or wrong nesting in YAML | Compare against the validate output |
Exercises
Exercise
You edited ../src/ingest.py and ran databricks bundle run -t dev daily_etl, but the job still executed the old code. What went wrong, and what should you do?
Show answer
run executes the last deployed version, not your local files. Run databricks bundle deploy -t dev to upload the change, then run the job again.
Exercise
How can you see which value of catalog the prod target will use without deploying anything?
Show answer
Run databricks bundle validate -t prod -o json and read the resolved variables and resource settings in the output.