Sub topic 17
CI/CD and Databricks Asset Bundles
This chapter assumes you can work in a Git folder: branch, commit, push, and open a pull request. It also assumes you know how a notebook task reads widget parameters and that you have seen the notebook source format. Here you move from "code lives in Git" to "code is tested and deployed from Git automatically".
Why Git folders alone are not enough
A Git folder gives you version control inside the workspace. It does not give you a controlled release process. Three problems show up as a team grows:
- A job that points at a Git folder runs whatever is checked out there, and someone can switch that folder's branch.
- Job definitions (schedule, cluster, parameters) live in the workspace UI, not in Git. They cannot be reviewed in a pull request.
- Moving work from dev to prod by hand means clicking through the UI, which is slow and easy to get wrong.
Continuous integration and continuous delivery (CI/CD) fixes this. CI runs checks on every change. CD deploys a change that passed those checks to a target environment.
What a Databricks Asset Bundle is
A Databricks Asset Bundle (DAB) is a project that describes your code and your Databricks resources as files. The central file is databricks.yml. It declares:
- The bundle name.
- Resources such as jobs and pipelines.
- Targets, which are the environments (for example
devandprod) you deploy to.
You work with a bundle through the Databricks CLI. The CLI reads the files, uploads the source to the workspace, and creates or updates the declared resources.
A typical layout:
orders_pipeline/
databricks.yml
src/
daily_load.py
tests/
test_transforms.pyA minimal bundle
The notebook src/daily_load.py is a source-format notebook that reads the run_date widget from earlier in this tutorial:
# Databricks notebook source
dbutils.widgets.text("run_date", "2026-01-01", "Run date")
run_date = dbutils.widgets.get("run_date")
print(f"Processing {run_date}")The matching databricks.yml defines one job and two targets:
bundle:
name: orders_pipeline
variables:
node_type_id:
description: Worker node type for the job cluster
default: i3.xlarge
targets:
dev:
mode: development
default: true
workspace:
host: https://adb-1111111111111111.11.azuredatabricks.net
prod:
mode: production
workspace:
host: https://adb-2222222222222222.12.azuredatabricks.net
root_path: /Workspace/Shared/.bundle/${bundle.name}/${bundle.target}
run_as:
service_principal_name: "00000000-0000-0000-0000-000000000000"
resources:
jobs:
daily_load:
name: daily_load
tasks:
- task_key: load
job_cluster_key: main
notebook_task:
notebook_path: ./src/daily_load.py
base_parameters:
run_date: "2026-01-01"
job_clusters:
- job_cluster_key: main
new_cluster:
spark_version: 15.4.x-scala2.12
node_type_id: ${var.node_type_id}
num_workers: 1Replace the host URLs, the node type, and the service principal ID with values from your environment. The node type shown is an AWS example. Azure and GCP use different names.
Some points about this file:
base_parameterssupplies the widget value. The widget name and the parameter key must match exactly.mode: developmentprefixes deployed resource names with your username and pauses schedules. This keeps personal test deployments from colliding with each other or running on a timer.mode: productionchecks that the deployment is set up safely. For example, it expects a fixedroot_pathand arun_asidentity.run_asmakes the production job run as a service principal, not as the person who happened to deploy it.${var.node_type_id}and${bundle.target}are substitutions resolved when the bundle is deployed.
The bundle commands
Run these from the bundle folder:
databricks bundle validate -t dev
databricks bundle deploy -t dev
databricks bundle run -t dev daily_load
databricks bundle destroy -t devvalidatechecks the configuration and reports schema errors.deployuploads files and creates or updates the job.runstarts the job and streams its status.destroydeletes what the bundle deployed to that target.
Deployment is declarative. You describe the desired state, and the CLI works out what to create, change, or remove. If you delete a job from databricks.yml and deploy again, the job is removed from that target.
Where bundles and Git folders fit
The two tools have different roles.
| Concern | Git folder | Bundle |
|---|---|---|
| Interactive editing and debugging | Yes | No |
| Branch, commit, push from the UI | Yes | No |
| Job and cluster definitions as code | No | Yes |
| Repeatable deploy to several environments | No | Yes |
| Runs in CI without a person | Awkward | Yes |
A common pattern: developers edit in a personal Git folder or a local IDE, push to a feature branch, and the bundle deploys that branch to a dev target. Production never runs from someone's Git folder. It runs from a deployed bundle.
A CI workflow
This GitHub Actions workflow validates the bundle on pull requests, runs unit tests, and deploys to prod after a merge to main:
name: ci-cd
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- run: pip install pytest
- run: pytest tests/
- uses: databricks/setup-cli@main
- run: databricks bundle validate -t dev
env:
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
deploy:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: databricks/setup-cli@main
- run: databricks bundle deploy -t prod
env:
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}The CLI authenticates with the OAuth client ID and secret of a service principal. Store them as repository secrets. Never write them into databricks.yml or the workflow file. Pin setup-cli to a released version tag for reproducible builds, since main changes over time.
Common errors
- Notebook not found at deploy time. Paths in
notebook_pathare relative to the file that declares them. A wrong relative path fails onvalidateordeploy. - Source file lacks the notebook header. A
.pyfile without# Databricks notebook sourceis deployed as a plain file, and the notebook task cannot treat it as a notebook. - Parameter name mismatch. If the key in
base_parametersdiffers from the widget name, the notebook silently uses the widget's default value. - Editing the deployed copy. Changes made in the workspace to a bundle-managed job or notebook are overwritten on the next deploy. Edit the source in Git.
- Deploying prod as yourself. Without
run_as, the job runs with the deployer's permissions. When that person leaves, the job can break. - Shared dev state. Two people deploying to the same target without
mode: developmentcan overwrite each other's resources.
Choosing a release approach
- Few jobs, one workspace, low change rate: a job that reads notebooks from a Git source may be enough. See the previous chapter.
- Several environments, reviewed job configuration, service principal execution: use a bundle.
- Both interactive work and release control: develop in Git folders, release through bundles. This is the pattern the next chapter builds on.
Exercise
Your bundle's prod job runs and prints the default date, even though your CI pipeline intended a different one. The notebook uses dbutils.widgets.text("run_date", "2026-01-01"), and databricks.yml sets base_parameters with the key date. What is wrong, and how do you fix it?
Show answer
The key in base_parameters (date) does not match the widget name (run_date). The widget therefore keeps its default value. Rename the key to run_date in databricks.yml, run databricks bundle validate, and redeploy.
Exercise
Why should the prod target set run_as to a service principal, and why should CI authenticate with a service principal's OAuth credentials stored as secrets?
Show answer
A service principal is not tied to a person, so jobs and deployments keep working when staff change, and its permissions can be limited to what the pipeline needs. Storing the credentials as CI secrets keeps them out of the repository and its history.