Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredJoin 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
I’m a DevOps engineer automating CI/CD deployments to a Microsoft Fabric Dev/Test workspace using Azure DevOps. We are using a service principal (service account) for authentication.
✅ Authentication completes successfully, but during the deployment stage, we receive the following error:
DefaultAzureCredential failed to retrieve a token from the included credentials.
This happens when the deployment script (deploy.py) runs, even though the service principal is authenticated earlier in the pipeline.
To build a secure, automated Azure DevOps pipeline that:
Solved! Go to Solution.
Hi @Shiva3 ,
Great question—this is a common stumbling block when automating Fabric deployments with Azure DevOps and service principals. Here’s a detailed breakdown and best practices:
Different Contexts in Pipeline:
Authentication might succeed during the initial stages (e.g., in Azure DevOps tasks), but when the deployment script (deploy.py) runs, it could be executed in a different context or environment variable scope. The DefaultAzureCredential flow checks multiple credential sources and may not pick up your service principal as expected during the script run.
Missing Environment Variables:
Ensure that all required environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET) are available in the context where deploy.py executes—not just in the pipeline, but for any subprocesses as well.
Token Caching/Expiration:
If there’s a delay or context switch, the acquired token may expire or not be forwarded properly between steps.
User vs. Service Principal Permissions:
Sometimes, the initial authentication uses a user identity, but the deploy script is forced to use a service principal, which may lack certain permissions on the Fabric workspace or resources.
Required Permissions:
Double-check that your service principal has all the necessary permissions on the Fabric workspace (Contributor or higher, Data Admin roles if needed).
Supported SDK/CLI:
Make sure you’re using the latest Azure SDKs compatible with Microsoft Fabric, and that your service principal is granted necessary RBAC roles both in Azure and in Fabric itself.
Service Connection in Azure DevOps:
If using an Azure Resource Manager service connection, verify that it’s set to use the correct service principal and that it’s available to all pipeline tasks and scripts.
Best Practice:
Set the required environment variables explicitly in the pipeline before running your Python deployment script, so DefaultAzureCredential always picks up the correct credentials.
Example YAML snippet:
- task: Bash@3 env: AZURE_CLIENT_ID: $(servicePrincipalId) AZURE_TENANT_ID: $(tenantId) AZURE_CLIENT_SECRET: $(servicePrincipalKey) inputs: targetType: 'inline' script: | python deploy.py
Python (deploy.py) snippet:
from azure.identity import DefaultAzureCredential from azure.mgmt.resource import ResourceManagementClient credential = DefaultAzureCredential() client = ResourceManagementClient(credential, "<subscription_id>") # ... your deployment logic ...
Extra Tips:
Let me know if you need a full working pipeline example or if you hit any other errors—happy to help you troubleshoot further!
Hi @Shiva3 ,
Great question—this is a common stumbling block when automating Fabric deployments with Azure DevOps and service principals. Here’s a detailed breakdown and best practices:
Different Contexts in Pipeline:
Authentication might succeed during the initial stages (e.g., in Azure DevOps tasks), but when the deployment script (deploy.py) runs, it could be executed in a different context or environment variable scope. The DefaultAzureCredential flow checks multiple credential sources and may not pick up your service principal as expected during the script run.
Missing Environment Variables:
Ensure that all required environment variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET) are available in the context where deploy.py executes—not just in the pipeline, but for any subprocesses as well.
Token Caching/Expiration:
If there’s a delay or context switch, the acquired token may expire or not be forwarded properly between steps.
User vs. Service Principal Permissions:
Sometimes, the initial authentication uses a user identity, but the deploy script is forced to use a service principal, which may lack certain permissions on the Fabric workspace or resources.
Required Permissions:
Double-check that your service principal has all the necessary permissions on the Fabric workspace (Contributor or higher, Data Admin roles if needed).
Supported SDK/CLI:
Make sure you’re using the latest Azure SDKs compatible with Microsoft Fabric, and that your service principal is granted necessary RBAC roles both in Azure and in Fabric itself.
Service Connection in Azure DevOps:
If using an Azure Resource Manager service connection, verify that it’s set to use the correct service principal and that it’s available to all pipeline tasks and scripts.
Best Practice:
Set the required environment variables explicitly in the pipeline before running your Python deployment script, so DefaultAzureCredential always picks up the correct credentials.
Example YAML snippet:
- task: Bash@3 env: AZURE_CLIENT_ID: $(servicePrincipalId) AZURE_TENANT_ID: $(tenantId) AZURE_CLIENT_SECRET: $(servicePrincipalKey) inputs: targetType: 'inline' script: | python deploy.py
Python (deploy.py) snippet:
from azure.identity import DefaultAzureCredential from azure.mgmt.resource import ResourceManagementClient credential = DefaultAzureCredential() client = ResourceManagementClient(credential, "<subscription_id>") # ... your deployment logic ...
Extra Tips:
Let me know if you need a full working pipeline example or if you hit any other errors—happy to help you troubleshoot further!
User | Count |
---|---|
80 | |
43 | |
16 | |
11 | |
7 |
User | Count |
---|---|
93 | |
88 | |
27 | |
8 | |
8 |