Sub topic 2
Installing the Databricks CLI and authenticating
This chapter assumes you know the Databricks workspace, notebooks, and jobs, and that you are comfortable in a terminal. Bundles are deployed with the Databricks CLI, so you need a current CLI and a working login before any later chapter's commands will run.
Which CLI you need
Bundle commands (databricks bundle ...) exist only in the newer, standalone Databricks CLI, version 0.205 or later. The older Python package named databricks-cli (versions 0.18 and below) does not support bundles. If pip install databricks-cli was your install method, switch to the standalone CLI.
Installing the CLI
Pick the method for your operating system.
# macOS or Linux with Homebrew
brew tap databricks/tap
brew install databricks
# Windows with WinGet
winget install Databricks.DatabricksCLI
# Any Linux or macOS shell, using the install script
curl -fsSL https://raw.githubusercontent.com/databricks/setup-cli/main/install.sh | shThen confirm the version:
databricks --versionThe output should show 0.205.0 or higher. If an older databricks command appears first on your PATH, remove it or reorder PATH so the new binary wins.
How authentication works
The CLI needs two facts to talk to a workspace: where it is (the host URL) and who you are (a credential). It stores these in a configuration profile, a named section in the file ~/.databrickscfg. Bundles use a profile, environment variables, or the workspace.host setting in databricks.yml to pick the workspace.
For interactive work, use OAuth user-to-machine (U2M) login. It opens a browser, you sign in, and the CLI stores a short-lived token that it refreshes for you. No long-lived secret is written to disk.
databricks auth login --host https://<your-dev-workspace-url>The command asks for a profile name. Choose something descriptive, such as dev, so you can tell profiles apart later.
Checking your profiles
List what you have configured and whether each profile can authenticate:
databricks auth profilesTo confirm that a profile reaches the right workspace as the right user, ask the workspace who you are:
databricks current-user me --profile devThe response contains your user name. If it prints a different workspace's user or fails, fix the profile before you deploy anything.
Using a profile with bundles
Commands accept --profile (or -p). A bundle command can also read the host from the target in databricks.yml, as the example in the Topic Spine does with workspace.host. When the host in the target matches the host of exactly one profile, the CLI uses that profile automatically. To be explicit, name it:
databricks bundle validate -t dev --profile devYou can also set the profile key under a target's workspace block, which keeps the choice in source control. Do not put tokens in databricks.yml.
Authentication for automation
Interactive login does not work on a build server, because no one can approve a browser prompt. For unattended use, authenticate as a service principal, a non-human identity. The CLI supports OAuth machine-to-machine (M2M) with a client ID and secret, supplied as environment variables:
export DATABRICKS_HOST="https://<your-workspace-url>"
export DATABRICKS_CLIENT_ID="<service-principal-application-id>"
export DATABRICKS_CLIENT_SECRET="<oauth-secret>"
databricks current-user meStore the secret in your CI system's secret store, never in the repository. A later chapter covers CI/CD in full.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `unknown command "bundle"` | Legacy `databricks-cli` is first on `PATH` | Install the standalone CLI and check `databricks --version` |
| `cannot configure default credentials` | No profile, host, or environment variables found | Run `databricks auth login` or export the variables |
| Deploys to the wrong workspace | A default profile or `DATABRICKS_HOST` overrides your intent | Pass `--profile` explicitly and check `databricks current-user me` |
| Login works but expires | OAuth token needs refreshing | Run `databricks auth login` again |
Exercise
You run databricks bundle deploy -t prod on a laptop and it reaches the dev workspace. Name two things to check.
Show answer
Check for DATABRICKSHOST or other DATABRICKS* environment variables in your shell that override the profile. Also check which profile is used: the prod target's workspace.host may not match any profile, so a default profile was chosen. Fix it by passing --profile explicitly and confirming with databricks current-user me --profile <name>.
Exercise
Why is OAuth M2M with a service principal used in CI instead of databricks auth login?
Show answer
The interactive login needs a person to approve a browser prompt, which a build server cannot do. M2M uses a client ID and secret from environment variables, so the pipeline authenticates unattended as a non-human identity.