Implementing CI/CD · Topic 2 of 2
Declarative Automation Bundles and the Databricks CLI
Databricks DEA bundles: databricks.yml, variables and target overrides, development and production modes, and bundle validate, deploy, run and destroy.
- 5 min
- Includes a diagram
- The bundle is defined in
databricks.yml; jobs and pipelines are resources in it. - Reference variables with
${var.name}; targets override defaults per environment. - Precedence:
--var, thenBUNDLE_VAR_<name>, then the overrides file, then the target override, then the default.
What it is
Declarative Automation Bundles (formerly Databricks Asset Bundles) describe a project as code: its source files plus the jobs, pipelines and other workspace resources that run them. The description lives in databricks.yml at the root of the repository.
The same bundle deploys to several targets, such as dev, test and prod. Variables and target overrides change what differs between environments, so the code itself is never copied or edited per environment.
How it works
The configuration file
A bundle has a name, resource definitions and targets. Resources include Lakeflow Jobs (jobs) and Lakeflow Declarative Pipelines (pipelines).
bundle:
name: sales_etl
resources:
jobs:
daily_sales:
tasks:
- task_key: load
notebook_task: { notebook_path: ./src/load.ipynb }
Deploying uploads the files and creates or updates the defined jobs and pipelines in the target workspace. A later deploy updates the same resources instead of creating duplicates.
Variables
Declare custom variables under variables and reference them with ${var.<name>}. A variable without a default must be given a value at deploy time.
variables:
catalog:
description: Target catalog
default: dev_catalog
targets:
prod:
variables:
catalog: prod_catalog
Built-in substitutions also exist, such as ${bundle.target} and ${workspace.current_user.userName}. A lookup variable resolves an object's ID from its name, for example a cluster or SQL warehouse, so IDs are never hard coded.
| Way to set a value | Precedence |
|---|---|
--var="catalog=qa_catalog" on the command line | 1, highest |
BUNDLE_VAR_catalog environment variable | 2 |
.databricks/bundle/<target>/variable-overrides.json | 3 |
targets.<target>.variables in the config | 4 |
The variable's default | 5, lowest |
Variables resolve at deployment time. To pass a value to each job run, use job parameters instead.
Targets and deployment modes
Each target sets a workspace and can override variables and resource settings. One target is usually marked default: true, used when no target is given.
| Mode | What the platform does |
|---|---|
development | Prefixes resource names with [dev <user>], tags them dev, pauses all schedules and triggers, marks pipelines as development |
production | Requires pipelines with development: false, checks the Git branch if one is set, recommends a service principal in run_as |
Development mode lets several developers deploy the same bundle to one workspace without overwriting each other or starting scheduled runs.
CLI commands
The Databricks CLI runs every bundle step, locally or in a CI/CD pipeline.
databricks bundle validate -t prod
databricks bundle deploy -t prod
databricks bundle run -t prod daily_sales
databricks bundle destroy -t dev
| Command | Purpose |
|---|---|
bundle init | Create a new bundle from a template |
bundle validate | Check the configuration and show resolved values; deploys nothing |
bundle deploy | Upload files and create or update resources in the target |
bundle run | Start a deployed job or pipeline by its resource key |
bundle destroy | Delete the resources and files this bundle deployed |
Promotion in CI/CD
A pull request runs validate and deploys to dev or test. Merging to main deploys the same commit to prod.
The CI system authenticates as a service principal, for example with DATABRICKS_HOST, DATABRICKS_CLIENT_ID and DATABRICKS_CLIENT_SECRET, not a person's credentials. Production then never depends on one user's account.
How the exam asks about this
- "Prod writes to a different catalog than dev, with the same code." A variable referenced as
${var.catalog}with a target override for prod. - "Check the bundle for errors in the pipeline before anything is deployed." Run databricks bundle validate.
- "Two developers deploy the same bundle to one dev workspace without clashing." Use a target with mode: development, which prefixes names per user and pauses schedules.
What to remember for the exam
- The bundle is defined in
databricks.yml; jobs and pipelines are resources in it. - Reference variables with
${var.name}; targets override defaults per environment. - Precedence:
--var, thenBUNDLE_VAR_<name>, then the overrides file, then the target override, then the default. validatechecks,deploycreates or updates,runstarts,destroyremoves.- Development mode prefixes names and pauses schedules; production mode suits service principal deployments.
- CI/CD should authenticate as a service principal.
databricks bundle deploy does not start anything. A question asking to execute the job after deployment needs databricks bundle run with the resource key.
Common mistakes
Copying notebooks per environment. Separate copies drift apart. Keep one codebase and let targets and variables carry the differences.
Confusing variables with job parameters. Bundle variables are fixed when the bundle deploys. A value that must change on each run belongs in a job parameter.
Expecting dev deployments to run on schedule. Development mode pauses schedules and triggers, so a scheduled job deployed to a development target does not start by itself.
Check yourself
Which value wins when a variable has a default, a prod target override and a --var flag?
The --var flag, because the command line has the highest precedence, then environment variables, the overrides file, the target override and finally the default.
What does databricks bundle validate do?
It checks the bundle configuration and shows the resolved settings without deploying anything to the workspace.
What happens to resource names in a development mode target?
They get a [dev username] prefix, so each developer's deployment is separate and its schedules and triggers are paused.
Topic 2 of 2 in Implementing CI/CD
Test yourself on Implementing CI/CD
The full Databricks Data Engineer Associate question bank has 598 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Databricks. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.