Let’s Get Certified
Module 09 / 21 · The platform

Version control and CI/CD

Move a change from a Git branch into a deployment target. Define bundle resources and check, deploy, and run them with the CLI.

Git vocabulary you should know

Git is a distributed version control system: every clone holds the full history, so you can commit locally and exchange commits with a remote.

TermMeaning
RepositoryThe container for a codebase and its full history
CommitA recorded set of changes (one or many files) with a message
BranchAn independent line of development for isolated changes. The default branch is usually main (formerly master)
RemoteA named reference to a copy of the repo hosted elsewhere (GitHub, GitLab, Azure DevOps) used to exchange commits
CloneCreate a full local copy of a remote repo, including history
CheckoutSwitch to another branch or commit
Stage (add)Select which changes go into the next commit. In a Databricks Git folder you tick the changed files in the Git dialog
FetchDownload remote commits without changing your branch
PullFetch and merge remote changes into your current branch
PushUpload your local commits to the remote
MergeCombine the histories of two branches
ResetDiscard or undo local changes

Git folders (formerly Repos)

A Git folder is a workspace folder linked to a remote Git repository: GitHub, GitLab, Azure DevOps, Bitbucket, AWS CodeCommit and others. You authenticate with a personal access token or a Databricks GitHub App, set under User settings, Linked accounts.

Setting up a Git folder in practice

Create Git folder dialog
In the UI. Workspace, Create, Git folder: paste the repository URL, pick the Git provider, name the folder. Sparse checkout mode clones only part of a large repository.
  • Create one from Workspace, Create, Git folder (or New, Git folder). Git folders can live anywhere in the workspace; there is no longer a separate top-level Repos area to look in.
  • Paste the repository's HTTPS URL. Private repositories need authentication: link GitHub through the Databricks GitHub App or a personal access token.
  • Sparse checkout clones only selected subdirectories of a large repository.
  • Error "GitHub account does not have access" for an organization repository: the Databricks GitHub App must be installed on that organization or repository by someone with admin rights on it.
  • Git is attached at the folder level. To version an existing notebook, move it into the Git folder, then commit and push from the Git dialog.
  • "Save now" in a notebook creates a revision in its version history, not a Git commit.

What you can do in the UI

  • Clone a remote repo into a Git folder.
  • Create a branch and switch branches from the Git dialog (branch name button at the top of a notebook or folder).
  • See changed files, write a message, commit and push in one step.
  • Pull remote changes. Resolve merge conflicts in the UI.
  • Merge and rebase branches; reset to discard local changes.
  • Create a pull request: the Git dialog links to the Git provider, where the PR is opened, reviewed and merged. Code review happens in the provider, not Databricks.
Exam focus

The development workflow: create a feature branch in a Git folder, edit notebooks, commit and push, open a PR in the Git provider, merge to main, then CI/CD deploys. Notebooks are stored in Git as source files (.py with # Databricks notebook source header, or .ipynb), so diffs are readable.

Typical layout: each developer has their own Git folder under their user folder for development. Production code is deployed by automation, not edited by hand in production.

Git folders vs notebook revision history

The video reports at least one exam question comparing Databricks Repos (now Git folders) with "native notebook versioning". In Databricks this means the revision history every notebook keeps automatically.

Git foldersNotebook revision history
ScopeWhole project (notebooks, .py files, configs) in a remote Git repoOne notebook at a time
BranchingCreate, switch, merge, rebase branchesNone, a single linear list of saved versions
CollaborationCommit, push, pull; pull requests and review in the Git providerRestore an earlier version, add comments to a version
CI/CDIntegrates with CI/CD tools (GitHub Actions, Azure DevOps) and bundlesNo CI/CD integration
StorageRemote Git provider, versioned outside the workspaceInside the workspace only
Exam framing

Choose Git folders whenever a question mentions branches, pull requests, code review, CI/CD or deploying the same code to several environments. Features such as fork, star, watch and issues belong to the Git provider (for example GitHub), not to Databricks. Authenticate with a scoped personal access token or the Databricks GitHub App, and revoke tokens you no longer need.

Declarative Automation Bundles New exam

Declarative Automation Bundles (formerly Databricks Asset Bundles, DABs) define your project as code: source files plus YAML describing resources such as jobs, pipelines, dashboards, schemas and volumes. The same bundle deploys to dev, test and prod with environment-specific settings. This is Databricks' recommended CI/CD approach.

Anatomy of databricks.yml

bundle:
  name: sales_etl

include:
  - resources/*.yml

variables:
  catalog:
    description: Target catalog
    default: dev_catalog
  db_password:
    description: Database password, supplied at deploy time

resources:
  jobs:
    daily_sales:
      name: daily_sales
      tasks:
        - task_key: ingest
          notebook_task:
            notebook_path: ./src/ingest.py
            base_parameters:
              catalog: ${var.catalog}
        - task_key: transform
          depends_on:
            - task_key: ingest
          pipeline_task:
            pipeline_id: ${resources.pipelines.sales_pipeline.id}

targets:
  dev:
    mode: development
    default: true
    workspace:
      host: https://dev-workspace.cloud.databricks.com
  prod:
    mode: production
    workspace:
      host: https://prod-workspace.cloud.databricks.com
    variables:
      catalog: prod_catalog
    run_as:
      service_principal_name: 6f1c...-sp

Key concepts

  • Targets: named environments (dev, test, prod). Settings under a target override the top-level settings for that target only.
  • Variables: declared in variables, used as ${var.name}. Values can come from (highest priority first): the --var="name=value" CLI option, an environment variable BUNDLE_VAR_name, a target's variables override, the variable's default. Lookups such as lookup: cluster_policy: "Prod policy" resolve an object name to its ID.
  • Substitutions: ${bundle.target}, ${workspace.current_user.userName}, ${resources.jobs.x.id}.
  • mode: development: prefixes resource names with [dev <user>], pauses schedules and triggers, deploys to the user's own folder so developers do not collide.
  • mode: production: checks production settings, including development flags on pipelines and a target Git branch when configured. Databricks recommends a service principal as the production run identity.
  • Templates: databricks bundle init starts from a template (default Python, default SQL, pipelines, custom).
Secrets in bundles

Do not hardcode a password in databricks.yml or the notebook. Keep runtime credentials in a secret scope and read them through dbutils.secrets.get. A CI environment can set deployment-time variables with BUNDLE_VAR_<variable_name>. Interpolating a password into an ordinary job parameter would still expose it in the deployed configuration.

The Databricks CLI

databricks auth login --host https://my-workspace.cloud.databricks.com   # OAuth login, saves a profile
databricks bundle init                  # create a bundle from a template
databricks bundle validate -t dev       # check YAML and resolve variables
databricks bundle deploy -t dev         # upload files and create/update resources
databricks bundle run -t dev daily_sales   # run a job or pipeline defined in the bundle
databricks bundle summary -t prod       # show deployed resources and links
databricks bundle destroy -t dev        # delete deployed resources and files
databricks bundle deployment bind ...   # link an existing workspace resource to the bundle
databricks bundle generate job --existing-job-id 123   # create bundle YAML from an existing job

Other CLI groups manage workspace assets directly: databricks jobs, databricks clusters, databricks secrets create-scope / put-secret, databricks fs, databricks workspace, databricks repos. Profiles live in ~/.databrickscfg. In CI, authenticate as a service principal (OAuth machine-to-machine) using environment variables such as DATABRICKS_HOST, DATABRICKS_CLIENT_ID, DATABRICKS_CLIENT_SECRET.

Developing locally: VS Code extension and Databricks Connect

Databricks Connect is a client library for the Databricks Runtime. You write Spark code in your IDE (VS Code, PyCharm, IntelliJ, RStudio Desktop, notebook servers, custom apps) in Python, R or Scala, and it runs on Databricks compute (a cluster or serverless). It is built on open source Spark Connect: a decoupled client-server architecture where the client sends DataFrame operations as unresolved logical plans to a remote Spark cluster.

The Databricks extension for Visual Studio Code bundles Databricks Connect, authentication, bundle projects and remote runs.

What the video lab does

  1. Install the Databricks extension from the VS Code Extensions view.
  2. Create a configuration: host = your workspace URL (copy it from the browser, remove the trailing slash), then choose OAuth (user-to-machine) or Personal access token, and name the profile (for example dev). Profiles are saved in ~/.databrickscfg.
  3. In the video, OAuth failed twice in VS Code even though the browser said "authenticated". The fix was to generate a personal access token (User settings, Developer, Access tokens) and use that. Never share tokens, and revoke them when finished.
  4. Create a project: the extension runs the bundle init flow. Template default-python, project name with letters, numbers and underscores only, include the stub notebook and Python package, use serverless compute. If it nests a folder inside your folder, move it up one level.
  5. Select the target (dev) and the compute (serverless in the video).
  6. Open src/<project>/main.py and click Run on Databricks. The run shows up under the job runs, and the output (5 rows of the NYC taxi sample read with spark.read.table) comes back to VS Code. It took about 1 min 23 s on serverless.
  7. Notebooks in the project can also be run on Databricks as a workflow; each cell's output is visible in the run.
from databricks.connect import DatabricksSession
spark = DatabricksSession.builder.serverless().getOrCreate()   # or .profile("dev")
spark.read.table("samples.nyctaxi.trips").show(5)

A CI/CD flow

  1. Developer works on a feature branch in a Git folder and deploys with bundle deploy -t dev to test.
  2. They push and open a pull request.
  3. CI (for example GitHub Actions) runs bundle validate and unit tests, and deploys to the test target for integration tests.
  4. After merge to main, CD runs bundle deploy -t prod as a service principal.

The same code is promoted unchanged; only target settings and variables differ.

Distractors to reject

Using notebook revision history as versioning, models in Unity Catalog to represent ETL jobs, or wheels in volumes alone are not the answer when a question asks for a modular way to deploy, version and orchestrate pipelines with CI/CD. The answer is bundles, versioned in Git.

Review a target change

A pull request points a production job at dev_catalog. Where should you fix the difference so the same transformation code can still run in development?

Check your reasoning

Use a bundle variable for the catalog and override it in the production target. Validate the target configuration before deployment.

Product reference

Declarative Automation Bundles in the Databricks documentation

Knowledge check

Version control and CI/CD quiz

Answer 4 questions. Check each answer for an explanation.