Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered
Hi All,
How do we attached ENV file to the notebooks when migrating through both deployment pipeline and devops.
Solved! Go to Solution.
Hi @Anonymous , thank you for reaching out to the Microsoft Fabric Community Forum.
Microsoft Fabric does not natively support attaching .env files to notebooks. However, you can manage environment variables in different ways:
from notebookutils import mssparkutils
# Get an environment variable
value = mssparkutils.env.getVariable("MY_ENV_VAR")
print(value)
import os
# Read .env file from Lakehouse Files
file_path = "/lakehouse/default/Files/config/.env"
with open(file_path, "r") as f:
for line in f:
key, value = line.strip().split("=")
os.environ[key] = value
# Access an environment variable
print(os.getenv("MY_CUSTOM_VAR"))
from notebookutils import mssparkutils
# Get a secret from Azure Key Vault
secret_value = mssparkutils.credentials.getSecret("my-key-vault", "MY_SECRET_KEY")
print(secret_value)
If this helps, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details.
Thank you.
Hi @Anonymous , thank you for reaching out to the Microsoft Fabric Community Forum.
To attach an ENV file to notebooks when migrating through both deployment pipeline and DevOps, and to re-tag different environments in the notebook, you can follow these steps:
If this helps, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details.
Thank you.
Hi @FabricPupil , Hope your issue is solved. If it is, please consider marking the answer 'Accept as solution', so others with similar issues may find it easily. If it isn't, please share the details.
Thank you.
Hi @FabricPupil , Hope your issue is solved. If it is, please consider marking the answer 'Accept as solution', so others with similar issues may find it easily. If it isn't, please share the details.
Thank you.
Hi @Anonymous , Hope your issue is solved. If it is, please consider marking the answer 'Accept as solution', so others with similar issues may find it easily. If it isn't, please share the details.
Thank you.
Hi @Anonymous , thank you for reaching out to the Microsoft Fabric Community Forum.
Microsoft Fabric does not natively support attaching .env files to notebooks. However, you can manage environment variables in different ways:
from notebookutils import mssparkutils
# Get an environment variable
value = mssparkutils.env.getVariable("MY_ENV_VAR")
print(value)
import os
# Read .env file from Lakehouse Files
file_path = "/lakehouse/default/Files/config/.env"
with open(file_path, "r") as f:
for line in f:
key, value = line.strip().split("=")
os.environ[key] = value
# Access an environment variable
print(os.getenv("MY_CUSTOM_VAR"))
from notebookutils import mssparkutils
# Get a secret from Azure Key Vault
secret_value = mssparkutils.credentials.getSecret("my-key-vault", "MY_SECRET_KEY")
print(secret_value)
If this helps, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details.
Thank you.
@v-hashadapu how are you getting getVariable
Hi @Anonymous
Microsoft Fabric does not have native support for attaching .env files directly to notebooks when migrating through deployment pipelines or DevOps. However, there are a few approaches you can consider for managing environment variables and secrets in Fabric notebooks:
Use NotebookUtils: Fabric provides NotebookUtils for working with environment variables. You can use the following code to access environment variables:
from notebookutils import mssparkutils
# Get an environment variable
value = mssparkutils.env.getVariable("VARIABLE_NAME")
Deployment Rules: When using deployment pipelines, you can create deployment rules to parameterize certain values, such as the default lakehouse, for each notebook instance. This allows you to change specific configurations when deploying across different environments.
Environment Resources: Fabric notebooks support an Environment Resources folder, which is a shared repository for collaboration across multiple notebooks. You could potentially store configuration files here, although it’s not recommended for sensitive information.
please accept this solution and give kudos if this is helpful.
thanks
Nilendra
Hi,
I am looking to call fabric env files which has built in libraries and allows public/custom libraries.
Hi @Anonymous,
Is this what you are looking for?
Wanted specifically on how to re-tag different env in notebook. eg. lakehouse can be specified in deployment rules, but I don't see it for env object (not unix env)
Hi @Anonymous , thank you for reaching out to the Microsoft Fabric Community Forum.
To attach an ENV file to notebooks when migrating through both deployment pipeline and DevOps, and to re-tag different environments in the notebook, you can follow these steps:
If this helps, please consider marking it 'Accept as Solution' so others with similar queries may find it more easily. If not, please share the details.
Thank you.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Fabric update to learn about new features.
User | Count |
---|---|
7 | |
4 | |
3 | |
3 | |
3 |