--- name: databricks-cli description: "Run Databricks CLI commands for day-to-day workspace operations. Use when: managing clusters, running jobs, listing or cancelling job runs, managing SQL warehouses, working with workspace files and notebooks, managing secrets and scopes, managing users/groups/service-principals/permissions, querying serving endpoints, interacting with ML experiments and model registry, using the filesystem (DBFS/Volumes), executing arbitrary REST API calls, or any general databricks CLI operation not covered by the bundle, install, UC, or ETL skills. Triggers: databricks cli, clusters, jobs, job runs, pipelines, SQL warehouse, workspace, notebooks, secrets, fs, dbfs, serving endpoints, model serving, experiments, model registry, users, groups, service principals, permissions, grants, alerts, queries, instance pools, libraries, repos, git credentials, account, api, REST." --- # Databricks CLI General-purpose skill for running Databricks CLI commands across all major command groups. For installation and authentication, see the `databricks-cli-install` skill. For Declarative Automation Bundles, see `databricks-automation-bundles`. For Unity Catalog browsing, see `databricks-unity-catalog`. ## Prerequisites - Databricks CLI v0.205+ installed and authenticated (see `databricks-cli-install` skill) - A valid configuration profile or environment variables set ## Concepts ### Command Structure ``` databricks [args] [--flags] ``` Get help at any level: ```bash databricks -h databricks clusters -h databricks clusters list -h ``` ### Global Flags | Flag | Description | |------|-------------| | `-p, --profile ` | Use a specific auth profile from `~/.databrickscfg` | | `--host ` | Override workspace host | | `--output json\|text` | Output format (default: text) | | `--debug` | Enable debug logging | | `--log-file ` | Write debug logs to file | | `--log-level ` | Log level: `trace`, `debug`, `info`, `warn`, `error` | **Always use `--output json`** when you need to parse or process results programmatically. ### JSON Input Many commands accept `--json` for structured input. On Linux/macOS, wrap in single quotes: ```bash databricks clusters create --json '{ "cluster_name": "my-cluster", "spark_version": "15.4.x-scala2.12", "node_type_id": "m5d.xlarge", "num_workers": 2 }' ``` ### Filtering Output with jq ```bash databricks clusters list --output json | jq '.[].cluster_name' databricks jobs list --output json | jq '.[] | select(.settings.name | test("etl"))' ``` ### Profiles ```bash databricks auth profiles # List all profiles databricks auth env --profile # Show profile details databricks auth token -p # Show current token + expiry ``` ## Workflow ### Step 1: Identify the User's Goal Route to the appropriate command group: | Goal | Command Group | Section | |------|--------------|---------| | Manage clusters | `clusters` | Compute | | Manage instance pools | `instance-pools` | Compute | | Manage cluster policies | `cluster-policies` | Compute | | Install libraries on clusters | `libraries` | Compute | | Create/run/manage jobs | `jobs` | Jobs | | Manage pipelines (DLT) | `pipelines` | Pipelines | | Manage SQL warehouses | `warehouses` | SQL | | Work with files (DBFS/Volumes) | `fs` | Workspace & Files | | Import/export notebooks | `workspace` | Workspace & Files | | Manage git repos | `repos` | Workspace & Files | | Manage secrets | `secrets` | Secrets | | Manage users/groups/SPs | `users`, `groups`, `service-principals` | Identity | | Manage permissions | `permissions` | Identity | | ML experiments | `experiments` | ML & Serving | | Model registry | `model-registry` | ML & Serving | | Model serving endpoints | `serving-endpoints` | ML & Serving | | Account-level admin | `account` | Account | | Call any REST API | `api` | API Escape Hatch | **⚠️ STOP**: If the user's intent maps to an existing skill, route there instead: - Unity Catalog browsing → `databricks-unity-catalog` - Bundle lifecycle → `databricks-automation-bundles` - CLI install/auth → `databricks-cli-install` - ETL notebooks → `databricks-etl-pyspark-notebooks` --- ### Compute #### Clusters ```bash databricks clusters list --output json databricks clusters get --output json databricks clusters create --json '' databricks clusters edit --json '' databricks clusters start databricks clusters restart databricks clusters delete # Terminate databricks clusters permanent-delete # Permanent delete databricks clusters pin databricks clusters unpin databricks clusters events --output json databricks clusters spark-versions # List available runtimes databricks clusters list-node-types --output json # List available node types ``` Create cluster example: ```bash databricks clusters create --json '{ "cluster_name": "dev-cluster", "spark_version": "15.4.x-scala2.12", "node_type_id": "m5d.xlarge", "autoscale": {"min_workers": 1, "max_workers": 4}, "autotermination_minutes": 30 }' ``` #### Instance Pools ```bash databricks instance-pools list --output json databricks instance-pools get --output json databricks instance-pools create --json '' databricks instance-pools edit --json '' databricks instance-pools delete --json '{"instance_pool_id": ""}' ``` #### Libraries ```bash databricks libraries all-cluster-statuses --output json databricks libraries cluster-status --output json databricks libraries install --cluster-id --json '{ "libraries": [{"pypi": {"package": "pandas==2.1.0"}}] }' databricks libraries uninstall --cluster-id --json '{ "libraries": [{"pypi": {"package": "pandas"}}] }' ``` --- ### Jobs ```bash databricks jobs list --output json databricks jobs list --name "etl" --output json # Filter by name databricks jobs get --output json databricks jobs create --json '' databricks jobs reset --json '' # Full replace databricks jobs update --json '' # Partial update databricks jobs delete ``` #### Running Jobs ```bash databricks jobs run-now # Trigger a run databricks jobs run-now --json '{ "notebook_params": {"key": "value"} }' databricks jobs list-runs --job-id --output json databricks jobs get-run --output json databricks jobs get-run-output --output json databricks jobs cancel-run databricks jobs cancel-all-runs databricks jobs repair-run --json '' # Retry failed tasks databricks jobs delete-run databricks jobs export-run --output json ``` #### One-time Runs (no saved job) ```bash databricks jobs submit --json '{ "run_name": "one-off-task", "tasks": [{ "task_key": "main", "notebook_task": { "notebook_path": "/Users/me/notebook" }, "new_cluster": { "spark_version": "15.4.x-scala2.12", "node_type_id": "m5d.xlarge", "num_workers": 1 } }] }' ``` --- ### Pipelines (Lakeflow / DLT) ```bash databricks pipelines list-pipelines --output json databricks pipelines get --output json databricks pipelines create --json '' databricks pipelines update --json '' databricks pipelines delete databricks pipelines start-update databricks pipelines start-update --full-refresh true databricks pipelines stop databricks pipelines list-updates --output json databricks pipelines get-update --update-id databricks pipelines list-pipeline-events --output json ``` For bundle-managed pipelines, see the `databricks-automation-bundles` skill. --- ### SQL #### Warehouses ```bash databricks warehouses list --output json databricks warehouses get --output json databricks warehouses create --json '' databricks warehouses edit --json '' databricks warehouses start databricks warehouses stop databricks warehouses delete ``` #### Execute SQL Statements **Important:** There is NO dedicated `databricks sql` or `databricks statement-execution` CLI command. SQL execution goes through the REST API escape hatch: ```bash databricks api post /api/2.0/sql/statements --json '{ "statement": "SELECT * FROM catalog.schema.table LIMIT 10", "warehouse_id": "", "wait_timeout": "50s" }' ``` The `databricks api` command uses the authenticated CLI profile -- no Bearer token or manual auth header is needed. #### SQL Without Unity Catalog (Hive Metastore) If the workspace uses the legacy Hive Metastore instead of Unity Catalog, SQL execution still works via the same API. Use two-level naming (`database.table`) instead of three-level: ```bash databricks api post /api/2.0/sql/statements --json '{ "statement": "SELECT * FROM default.my_table LIMIT 10", "warehouse_id": "", "wait_timeout": "50s" }' ``` Useful Hive Metastore discovery queries: - `SHOW DATABASES` -- list all databases - `SHOW TABLES IN ` -- list tables in a database - `DESCRIBE TABLE .` -- get table schema If no SQL warehouse exists, the alternative is to run SQL via a notebook on an all-purpose cluster (use the `databricks-etl-pyspark-notebooks` skill for that workflow). #### Alerts and Queries ```bash databricks alerts list --output json databricks alerts get --output json databricks alerts create --json '' databricks alerts delete databricks queries list --output json databricks queries get --output json ``` --- ### Workspace & Files #### Filesystem (DBFS and Volumes) ```bash databricks fs ls dbfs:/path/to/dir databricks fs ls /Volumes/catalog/schema/volume/path databricks fs cp local-file.csv dbfs:/uploads/file.csv databricks fs cp dbfs:/uploads/file.csv ./local-file.csv databricks fs cp local-dir/ dbfs:/uploads/dir/ --recursive databricks fs mkdir dbfs:/new-dir databricks fs rm dbfs:/old-file.csv databricks fs rm dbfs:/old-dir/ --recursive databricks fs cat dbfs:/path/to/file.txt ``` #### Workspace (Notebooks and Folders) ```bash databricks workspace list /Users/me --output json databricks workspace get-status /Users/me/notebook --output json databricks workspace export /Users/me/notebook --format SOURCE -o notebook.py databricks workspace export-dir /Users/me/project ./local-dir databricks workspace import ./notebook.py /Users/me/notebook --format SOURCE --language PYTHON databricks workspace import-dir ./local-dir /Users/me/project databricks workspace mkdirs /Users/me/new-folder databricks workspace delete /Users/me/old-notebook databricks workspace delete /Users/me/old-folder --recursive ``` #### Git Repos ```bash databricks repos list --output json databricks repos get --output json databricks repos create --json '{ "url": "https://github.com/org/repo", "provider": "gitHub", "path": "/Repos/me/my-repo" }' databricks repos update --json '{"branch": "main"}' databricks repos delete ``` --- ### Secrets ```bash databricks secrets list-scopes --output json databricks secrets create-scope databricks secrets delete-scope databricks secrets put-secret --string-value "" databricks secrets list-secrets --output json databricks secrets get-secret databricks secrets delete-secret ``` #### Secret ACLs ```bash databricks secrets list-acls --output json databricks secrets get-acl --principal databricks secrets put-acl --principal --permission MANAGE|READ|WRITE databricks secrets delete-acl --principal ``` --- ### Identity & Access #### Users ```bash databricks users list --output json databricks users get --output json databricks users create --json '{"userName": "user@example.com"}' databricks users delete ``` #### Groups ```bash databricks groups list --output json databricks groups get --output json databricks groups create --json '{"displayName": "data-engineers"}' databricks groups patch --json '{ "schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"], "Operations": [{"op": "add", "path": "members", "value": [{"value": ""}]}] }' databricks groups delete ``` #### Service Principals ```bash databricks service-principals list --output json databricks service-principals get --output json databricks service-principals create --json '{"displayName": "ci-bot", "active": true}' databricks service-principals delete ``` #### Permissions ```bash databricks permissions get --output json databricks permissions set --json '{ "access_control_list": [ {"group_name": "data-engineers", "permission_level": "CAN_MANAGE"} ] }' databricks permissions update --json '' ``` Object types: `clusters`, `cluster-policies`, `instance-pools`, `jobs`, `pipelines`, `notebooks`, `directories`, `repos`, `serving-endpoints`, `warehouses`, `registered-models`, `experiments`. --- ### ML & Serving #### Experiments (MLflow) ```bash databricks experiments list-experiments --output json databricks experiments get-experiment --output json databricks experiments get-by-name --experiment-name "/Users/me/experiment" databricks experiments create-experiment --name "/Users/me/new-experiment" databricks experiments search-runs --experiment-ids --output json databricks experiments delete-experiment --experiment-id ``` #### Model Registry ```bash databricks model-registry list-models --output json databricks model-registry get-model --name "my_model" --output json databricks model-registry get-latest-versions --name "my_model" --output json databricks model-registry search-model-versions --filter "name='my_model'" --output json databricks model-registry transition-stage --name "my_model" --version 3 --stage Production --archive-existing-versions ``` #### Serving Endpoints ```bash databricks serving-endpoints list --output json databricks serving-endpoints get --output json databricks serving-endpoints create --json '' databricks serving-endpoints update-config --json '' databricks serving-endpoints delete databricks serving-endpoints query --json '{ "inputs": [{"question": "What is Databricks?"}] }' databricks serving-endpoints logs --served-model-name databricks serving-endpoints build-logs --served-model-name ``` --- ### Account-Level Commands Account commands require account-level auth (`--host https://accounts.cloud.databricks.com --account-id `). ```bash databricks account users list --output json databricks account groups list --output json databricks account service-principals list --output json databricks account workspaces list --output json databricks account metastores list --output json databricks account budgets list --output json databricks account billable-usage download --start-month 2025-01 --end-month 2025-12 -o usage.csv ``` --- ### API Escape Hatch For any Databricks REST API endpoint not directly exposed as a CLI command: ```bash databricks api get /api/2.0/ --output json databricks api post /api/2.0/ --json '' databricks api put /api/2.0/ --json '' databricks api delete /api/2.0/ databricks api patch /api/2.0/ --json '' ``` Example — get current user: ```bash databricks api get /api/2.0/preview/scim/v2/Me --output json ``` Example — run SQL: ```bash databricks api post /api/2.0/sql/statements --json '{ "statement": "SHOW TABLES IN catalog.schema", "warehouse_id": "", "wait_timeout": "50s" }' ``` ## Stopping Points - After Step 1 if user intent is ambiguous (ask which operation) - Before any destructive operation (`delete`, `permanent-delete`, `destroy`) — confirm with the user - If authentication fails — route to `databricks-cli-install` skill ## Troubleshooting | Problem | Solution | |---------|----------| | `command not found: databricks` | CLI not installed. See `databricks-cli-install` skill. | | `Error: authentication required` | No valid profile or env vars. Run `databricks auth login --host `. | | `Error: ... 403 Forbidden` | User lacks permissions. Check with `databricks permissions get`. | | `Error: ... 404 Not Found` | Resource ID is wrong or resource was deleted. Verify with a `list` command. | | `Error: ... rate limit exceeded` | Too many API calls. Wait and retry, or batch operations. | | `--output json` not recognized | CLI version too old. Update: `brew upgrade databricks`. | | Profile not found | List profiles with `databricks auth profiles`. Check `~/.databrickscfg`. | | `Error: cluster is not running` | Start the cluster first: `databricks clusters start `. | | Timeout on SQL statement | Increase `wait_timeout` (max `50s`). For long queries, poll with statement ID. | ## Output This skill produces: - Databricks resource management via CLI (clusters, jobs, warehouses, endpoints, etc.) - JSON output from list/get commands for further processing - Created, updated, or deleted Databricks resources as requested