7

I want to use databricks cli:

databricks clusters list

but this requires a manual step that requires interactive work with the user:

databricks configure --token

Is there a way to use databricks cli without manual intervention so that you can run it as part of a ci/cd pipeline?

Alex Ott
  • 80,552
  • 8
  • 87
  • 132
Mor Shemesh
  • 2,689
  • 1
  • 24
  • 36

4 Answers4

5

You can just export the variables DATABRICKS_HOST and DATABRICKS_TOKEN. With those variables, you don't need a config file.

5

As mentioned above by @usingnamespace, and from the official docs:

CLI 0.8.0 and above supports environment variables, an environment variable setting takes precedence over the setting in the configuration file.

DATABRICKS_HOST
DATABRICKS_USERNAME
DATABRICKS_PASSWORD
DATABRICKS_TOKEN

With that, not only you will not be exposing sensitive data in clear text files (~/.databrickscfg), you won't need to add any more code to your script.

Marco Roy
  • 4,004
  • 7
  • 34
  • 50
Gee VB
  • 183
  • 3
  • 8
3

The following bash script, configured the databricks cli automatically:

echo "configuring databrick-cli authentication"

declare DATABRICKS_URL="https://westeurope.azuredatabricks.net"
declare DATABRICKS_ACCESS_TOKEN="authentication_token_generated_from_databricks_ux"

declare dbconfig=$(<~/.databrickscfg)
if [[ $dbconfig = *"host = "* && $dbconfig = *"token = "* ]]; then
  echo "file [~/.databrickscfg] is already configured"
else
  if [[ -z "$DATABRICKS_URL" || -z "$DATABRICKS_ACCESS_TOKEN" ]]; then
    echo "file [~/.databrickscfg] is not configured, but [DATABRICKS_URL],[DATABRICKS_ACCESS_TOKEN] env vars are not set"
  else
    echo "populating [~/.databrickscfg]"
    > ~/.databrickscfg
    echo "[DEFAULT]" >> ~/.databrickscfg
    echo "host = $DATABRICKS_URL" >> ~/.databrickscfg
    echo "token = $DATABRICKS_ACCESS_TOKEN" >> ~/.databrickscfg
    echo "" >> ~/.databrickscfg
  fi
fi
Mor Shemesh
  • 2,689
  • 1
  • 24
  • 36
  • apparently you can now log on with a username, and password... but on Azure i can never get it to work #voodoo – m1nkeh Apr 24 '19 at 12:33
  • I am trying to run this in R. Do you know how should I go about it using this bash script to run in R? – 89_Simple Sep 10 '19 at 10:13
2

This is a PowerShell version of the script.

write-host Configure databricks access
$Env:DATABRICKS_CONFIG_FILE = "$(System.DefaultWorkingDirectory)/.databrickscfg"
Set-Location $(System.DefaultWorkingDirectory)
Set-Content .databrickscfg "[DEFAULT]"
Add-Content .databrickscfg "host = https://westeurope.azuredatabricks.net/"
Add-Content .databrickscfg "token = $(db-token)"
hui chen
  • 1,004
  • 14
  • 19
  • To make the configure effective, the databricks-cli commands must be called in the same PS session. – hui chen Apr 12 '20 at 08:53