08-19-2022 06:53 AM
Hi Databricks Community,
I want to set environment variables for all clusters in my workspace.
The goal is to have environment (dev, prod) specific environment variables values.
Instead of set the environment variables for each cluster, a global script is desired.
I tried different scripts like
but environment variables are not available via
The global init script did not fail.
Any ideas?
Thank you!
08-30-2022 11:19 PM
Solution:
#!/bin/bash
echo export VARIABLE_NAME=VARIABLE_VALUE >> /etc/environment
The Shebang is required.
The environment variable can then be accessed via (Python):
my_variable = os.environ["VARIABLE_NAME"]
08-20-2022 04:07 AM
have you tried the widgets utils from databricks?
https://docs.microsoft.com/en-us/azure/databricks/notebooks/widgets
dbutils.widgets.text("database", "dev")
database_def = dbutils.widgets.getArgument("database")
print(database_def)
You can parametrize it when you run the scripts.
08-22-2022 12:16 AM
The cluster teminated after adding the first line to the global init script.
I think the widget utitliy is only for notebooks.
Doesn't the global init script have to be a valid sh/bash script?
08-30-2022 11:19 PM
Solution:
#!/bin/bash
echo export VARIABLE_NAME=VARIABLE_VALUE >> /etc/environment
The Shebang is required.
The environment variable can then be accessed via (Python):
my_variable = os.environ["VARIABLE_NAME"]
02-03-2023 12:51 AM
We have set the env variable at Global Init script as below,
sudo echo DATAENV=DEV >> /etc/environment
and we try to access the variable in notebook that run with "Shared" cluster mode.
import os
print(os.getenv("DATAENV"))
But the env variable is not accessible and getting value as "None".
However, when run the notebook with "No Isolation Shared" cluster, then the env variable is accessed successfully.
Any idea, is there any restriction in accessing environment variables at cluster mode level?
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group