Menu

Databricks course · Lesson 7 of 13

Databricks CI/CD: Git Folders, Bundles, the CLI and Tests

Ship Databricks code like software: Git folders for development, Declarative Automation Bundles for dev, test and prod targets, the Databricks CLI, unit tests and a CI pipeline.

  • Intermediate
  • 8 min read
  • Updated Nov 2026
On this page
  1. Git folders: Git inside the workspace
  2. Bundles: the whole project as code
  3. Development and production modes
  4. The CLI workflow
  5. Testing the code
  6. A CI pipeline
  7. Secrets and identities
  8. Common mistakes
  9. Interview angle
  10. Key takeaway

Notebooks make it easy to try ideas, and just as easy to break production by editing a live job. CI/CD on Databricks means the same thing as anywhere else: code lives in Git, changes go through review and automated tests, and a pipeline deploys the reviewed version to each environment. Databricks gives you three tools for it: Git folders for working with Git inside the workspace, Declarative Automation Bundles (formerly Databricks Asset Bundles) for describing jobs and pipelines as code, and the Databricks CLI for deploying them.

Git folders: Git inside the workspace

A Git folder (formerly Repos) links a workspace folder to a remote repository on GitHub, GitLab, Azure DevOps or Bitbucket. From the UI you can clone, create and switch branches, pull, commit and push, and open the provider’s page to raise a pull request.

The working pattern:

  1. Each engineer clones the repository into their own Git folder and works on a feature branch.
  2. They run and debug in notebooks attached to development compute.
  3. They commit and push, then open a pull request that CI tests and a colleague reviews.
  4. Only the merged code is deployed to test and production, by automation rather than by hand.

Git folders are for development. Production jobs should not point at someone’s Git folder; they should run code deployed by a bundle to a controlled location.

Bundles: the whole project as code

A bundle is a folder with a databricks.yml file that describes the project’s resources (jobs, pipelines, dashboards and more), the code they run, and the targets (environments) it can be deployed to. A typical layout:

orders-pipeline/
├── databricks.yml          # bundle name, variables, targets
├── resources/
│   └── daily_orders.job.yml
├── src/
│   └── orders/
│       ├── __init__.py
│       └── transforms.py   # pure functions, unit tested
├── notebooks/
│   └── build_silver.py     # thin entry point that calls src/
├── tests/
│   └── test_transforms.py
└── pyproject.toml

Keep logic in plain Python modules and keep notebooks thin. Modules can be imported by tests on a laptop or a CI runner; notebook cells cannot.

A databricks.yml with three targets:

bundle:
  name: orders-pipeline

include:
  - resources/*.yml

variables:
  catalog:
    description: Unity Catalog catalog to write to
    default: dev
  alert_email:
    default: [email protected]

targets:
  dev:
    mode: development
    default: true
    workspace:
      host: https://dev-workspace.cloud.databricks.com
  test:
    workspace:
      host: https://test-workspace.cloud.databricks.com
    variables:
      catalog: test
  prod:
    mode: production
    git:
      branch: main
    workspace:
      host: https://prod-workspace.cloud.databricks.com
    variables:
      catalog: prod
    run_as:
      service_principal_name: 00000000-0000-0000-0000-000000000000

Resources read variables with ${var.catalog}, and built-in substitutions such as ${bundle.target} and ${workspace.current_user.short_name} keep names apart per environment.

Development and production modes

The mode setting applies a group of sensible defaults:

mode: development mode: production
Resource names Prefixed with [dev your_name] so each developer gets their own copy Unchanged
Schedules and triggers Paused As defined
Pipelines Marked as development Must not be development
Checks Concurrent runs allowed, deployment lock off Validates the Git branch (if set) and that run-as and permissions are explicit

Databricks recommends deploying production as a service principal and setting run_as to one, so jobs do not depend on a person’s account.

The CLI workflow

The Databricks CLI drives bundles:

databricks bundle init                  # start from a template
databricks bundle validate -t dev       # check the YAML and resolve variables
databricks bundle deploy -t dev         # upload code and create or update resources
databricks bundle run -t dev daily_orders   # run a job defined in the bundle
databricks bundle deploy -t prod --var="catalog=prod"
databricks bundle destroy -t dev        # remove a developer's copy

deploy is idempotent: it creates resources the first time and updates them afterwards, so the YAML in Git stays the source of truth. Variable values can come from the target, from --var on the command line, or from environment variables named BUNDLE_VAR_<name>, which is how CI systems pass values without writing them into files.

Testing the code

Put transformations in functions that take and return DataFrames, then test them with PySpark’s testing helpers. This function cleans raw orders:

# src/orders/transforms.py
from pyspark.sql import DataFrame, Window, functions as F


def clean_orders(df: DataFrame) -> DataFrame:
    """Drop rows without an order id, tidy country codes and keep the latest row per order."""
    latest_first = Window.partitionBy("order_id").orderBy(F.col("updated_at").desc())
    return (
        df.where(F.col("order_id").isNotNull())
        .withColumn("country", F.upper(F.trim("country")))
        .withColumn("_rn", F.row_number().over(latest_first))
        .where("_rn = 1")
        .drop("_rn")
    )

And a test that runs on any machine with PySpark and Java:

# tests/test_transforms.py
import pytest
from pyspark.sql import SparkSession
from pyspark.testing import assertDataFrameEqual, assertSchemaEqual

from orders.transforms import clean_orders


@pytest.fixture(scope="session")
def spark():
    return SparkSession.builder.master("local[1]").getOrCreate()


def test_clean_orders_keeps_latest_and_tidies_country(spark):
    raw = spark.createDataFrame(
        [(1, " in", "2026-11-01"), (1, "IN ", "2026-11-02"), (None, "us", "2026-11-02"), (2, "us", "2026-11-01")],
        "order_id INT, country STRING, updated_at STRING",
    )
    expected = spark.createDataFrame(
        [(1, "IN", "2026-11-02"), (2, "US", "2026-11-01")],
        "order_id INT, country STRING, updated_at STRING",
    )
    result = clean_orders(raw)
    assertSchemaEqual(result.schema, expected.schema)
    assertDataFrameEqual(result, expected)  # row order is ignored by default
$ pytest -q
1 passed, 1 warning in 10.99s

With pythonpath = ["src"] under [tool.pytest.ini_options] in pyproject.toml, pytest finds the orders package. assertDataFrameEqual compares rows regardless of order by default and prints a readable difference when they do not match; DataFrame.transform lets you chain such functions in the notebook, as in raw.transform(clean_orders).

Unit tests cover logic. Integration tests cover the platform: deploy the bundle to a test target, run the job on a small fixed dataset, and check the output tables. Run them before production deployment, not on every commit.

A CI pipeline

A GitHub Actions workflow that tests every pull request and deploys main:

name: orders-pipeline
on:
  pull_request:
  push:
    branches: [main]

jobs:
  test-and-deploy:
    runs-on: ubuntu-latest
    env:
      DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
      DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
      DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install pyspark pytest && pytest -q
      - uses: databricks/setup-cli@main
      - run: databricks bundle validate -t prod
      - if: github.ref == 'refs/heads/main'
        run: databricks bundle deploy -t prod

The service principal’s OAuth client ID and secret live in the CI system’s secret store, never in the repository. Many teams add a test-target deployment and an integration run between validation and production.

Secrets and identities

  • Credentials the job needs at run time (a database password, an API key) belong in a Databricks secret scope and are read with dbutils.secrets.get(scope, key). They never appear in databricks.yml, notebooks or job parameters.
  • Values the deployment needs come from the CI secret store as environment variables (DATABRICKS_CLIENT_SECRET, or BUNDLE_VAR_<name> for bundle variables).
  • Production runs as a service principal with only the permissions its tables need, and only the CI identity can deploy to production.

Common mistakes

  1. Editing production jobs in the UI. The next deployment overwrites the change, or worse, the change is never recorded.
  2. Logic inside notebooks only. Nothing can be unit tested; move it into modules.
  3. Committing secrets. Tokens in YAML or notebooks end up in Git history forever. Use secret scopes and CI secrets.
  4. One shared target for everyone. Development mode gives each engineer a prefixed copy so they do not overwrite each other.
  5. Deploying as a person. Use a service principal for deployments and for run_as in production.

Interview angle

“How do you promote a Databricks job from dev to prod?” Describe a bundle in Git with dev, test and prod targets, and pull requests that run unit tests and bundle validate. Then a deployment to test with an integration run, and a deployment of main to production by a service principal, with secrets in secret scopes and the CI secret store. Mention that development mode prefixes names and pauses schedules.

Key takeaway

Keep everything in Git, describe jobs and pipelines in a bundle with one target per environment, test the logic as plain Python, and let a CI pipeline running as a service principal be the only thing that deploys to production.

By , Data Engineer and Founder of DataDank · Last reviewed Nov 2026 · Describes Declarative Automation Bundles (formerly Databricks Asset Bundles) and Git folders as documented in November 2026. The unit test was run on PySpark 4.0.1 with pytest locally and passes. The bundle YAML, CLI commands and CI workflow need a Databricks workspace and were checked against the documentation, not executed.

Progress is saved in this browser only. No account needed.

Search
Filter by type