Sub topic 9
Defining jobs and pipelines as a Databricks Asset Bundle
This chapter assumes you can read YAML, know what a Databricks job is, and have the Databricks CLI (version 0.205 or later) installed and authenticated to a workspace.
What a bundle is
A Databricks Asset Bundle (DAB) is a project folder that describes your jobs, pipelines, and their source files as code. The CLI reads the description and creates or updates those objects in a workspace. Because the description lives in Git, a pull request can change a job and a reviewer can see exactly what changed.
A bundle has three parts:
databricks.ymlis the root file. It names the bundle and declares targets.- Resource files hold job and pipeline definitions. The root file pulls them in with
include. - Your source code is referenced by relative path from the resource files.
Defining a job
The databricks.yml from the earlier layout chapter already includes resources/*.yml. Add a file resources/orders_job.yml:
resources:
jobs:
orders_job:
name: orders_job_${bundle.target}
job_clusters:
- job_cluster_key: main
new_cluster:
spark_version: 15.4.x-scala2.12
node_type_id: Standard_DS3_v2
num_workers: 1
tasks:
- task_key: build_orders
job_cluster_key: main
spark_python_task:
python_file: ../src/jobs/build_orders.pyThree details matter here:
orders_jobunderjobsis the resource key. You use it indatabricks bundle run.${bundle.target}is a substitution. It gives each environment its own job name, so dev and staging never collide.python_fileis relative to the resource file, not to the folder where you run the command. This is why the path starts with../.
A pipeline follows the same pattern under resources.pipelines, with a libraries list that points at your pipeline source files.
The deploy loop
Run these commands from the bundle root:
databricks bundle validate -t dev
databricks bundle deploy -t dev
databricks bundle run -t dev orders_jobvalidate checks the merged configuration without touching the workspace. deploy uploads files and creates or updates resources. run starts the job and waits for it to finish. Pass the same -t value to all three. Without it, the CLI uses the target marked default: true, which is usually dev.
Common errors
| Symptom | Likely cause |
|---|---|
| `validate` reports a file not found | A path in a resource file is relative to the wrong folder. Make it relative to that resource file. |
| Resource file has no effect | The file is not matched by `include`, or the top-level key is not `resources`. |
| Deploy changes the wrong workspace | You omitted `-t` and the default target applies. Pass `-t` in scripts. |
| Job exists twice after a rename | The bundle tracks resources by key. Changing the key creates a new job. Change `name` instead. |
Why this matters for CI/CD
A bundle gives CI a single, repeatable action: validate on every pull request, deploy on merge. The same files produce all three environments, and only the target changes. The next chapters cover the targets and how CI authenticates.
Exercise
You rename the resource key orders_job to orders_etl in resources/orders_job.yml, then deploy to dev. What happens to the existing deployed job, and how would you avoid it?
Show answer
The bundle tracks resources by key, so the CLI treats orders_etl as a new resource and creates a second job. It then removes the old one on the next deploy, which loses run history and any manual settings. To avoid this, keep the key stable and change only the name field.