我想使用databricks cli:
databricks clusters list
但这需要一个手动步骤,需要与用户进行交互工作:
databricks configure --token
有没有办法在没有手动干预的情况下使用 databricks cli,以便您可以将其作为 ci/cd 管道的一部分运行?
您可以将变量导出DATABRICKS_HOST并DATABRICKS_TOKEN。使用这些变量,您不需要配置文件。
如上所述,@usingnamespace和官方文档:
CLI 0.8.0 及更高版本支持环境变量,环境变量设置优先于配置文件中的设置。
DATABRICKS_HOST
DATABRICKS_USERNAME
DATABRICKS_PASSWORD
DATABRICKS_TOKEN
这样,您不仅不会在明文文件 (~/.databrickscfg( 中公开敏感数据,而且无需向脚本添加更多代码。
以下 bash 脚本自动配置了数据砖 cli:
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
这是脚本的PowerShell版本。
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)"