Sub topic 13
Validating, deploying, and running a bundle
This chapter assumes you have a working CLI profile (see the authentication chapters), can read YAML, and have a databricks.yml like the one in the previous chapter. It covers the bundle commands you run after the configuration is written.
The lifecycle at a glance
A bundle moves through four commands. Each one reads the same databricks.yml, and each one takes a target with -t.
| Command | What it does | Changes the workspace? |
|---|---|---|
| `bundle validate` | Checks the configuration and resolves variables | No |
| `bundle deploy` | Uploads files and creates or updates resources | Yes |
| `bundle run` | Starts a job or pipeline defined in the bundle | Yes (starts a run) |
| `bundle destroy` | Deletes the resources and files the bundle deployed | Yes |
Validate first
Validation catches syntax errors, unknown keys, and unresolved variables before anything is uploaded.
databricks bundle validate -t devOn success the command prints a summary of the bundle name, target, and workspace host. If a variable has no value, validation reports it. The cluster_id variable in the example has no default, so you must supply it with --var.
Deploy to a target
Deploying uploads your files to the workspace and creates or updates the job to match the configuration.
databricks bundle deploy -t dev --var cluster_id=<cluster-id>Three behaviors are worth knowing:
- Deploy is idempotent. Running it again with no changes leaves the job as it is, and running it after an edit updates the job in place.
- The bundle tracks what it created in a state file. This is how
deployknows which resources to update and howdestroyknows what to delete. - With
mode: development, resource names get a[dev <your-user-name>]prefix, and schedules are paused. Several people can deploy the same bundle without overwriting each other.
Run a resource
bundle run takes the resource key from databricks.yml, which is demo_job here, not the display name.
databricks bundle run -t dev --var cluster_id=<cluster-id> demo_jobThe command starts a run, prints a link to it, and waits until the run reaches a terminal state. If the run fails, the command exits with a non-zero status. This is what lets a CI pipeline stop on failure. Use --no-wait if you only want to start the run and return immediately.
Clean up with destroy
databricks bundle destroy -t devThe command lists what it will delete and asks for confirmation. Pass --auto-approve only in scripts where you are sure of the target.
databricks bundle validate -t dev && \
databricks bundle deploy -t dev --var cluster_id=<cluster-id> && \
databricks bundle run -t dev --var cluster_id=<cluster-id> demo_jobThe && chain stops at the first failing command, so a run never starts from a bundle that failed validation or deployment.
Common errors
- Variable has no value. You omitted
--var. Pass it on every command that resolves variables, or set aBUNDLE_VAR_cluster_idenvironment variable. - Wrong target or host. If
-tis omitted, the CLI uses the target markeddefault: true. Always pass-tin scripts so the target is explicit. - Unknown resource key in
run. Use the key underresources.jobs, and check it withbundle validate.
Exercise
Why does the chained command use && rather than ; between validate, deploy, and run?
Show answer
&& runs the next command only if the previous one exits successfully. With ;, deploy and run would still execute after a failed validation, which could deploy a broken bundle.