1. What is Environment-Specific Configuration?
In Azure DevOps, environment-specific configuration means maintaining different configuration values for each environment while using the same application code and build artifact.
For example, an ASP.NET Core Web API application may use different databases, API URLs, and secrets.
|
Configuration |
DEV |
SIT |
UAT |
PROD |
|---|---|---|---|---|
|
Environment |
Development |
SIT |
UAT |
Production |
|
Database |
Employee_Dev |
Employee_SIT |
Employee_UAT |
Employee_Prod |
|
API URL |
dev-api.example.com |
sit-api.example.com |
uat-api.example.com |
api.example.com |
|
Logging |
Debug |
Information |
Information |
Warning |
Main goal: Build the application once and deploy the same artifact across all environments using different configurations.
2. How do we manage different configurations?
There are four common approaches:
-
Variable Groups – Store environment-specific values in Azure DevOps.
-
appsettings files – Maintain ASP.NET Core configuration for each environment.
-
Azure Key Vault – Securely store passwords, connection strings, and API keys.
-
Pipeline variables – Define build and deployment settings in YAML.
For enterprise applications, these approaches are often combined.
3. Step 1 – Create Variable Groups
Navigate to:
Azure DevOps → Pipelines → Library → Variable groups
Create four groups:
DEV-Configuration
SIT-Configuration
UAT-Configuration
PROD-Configuration
Example values:
|
Variable |
DEV Group |
SIT Group |
PROD Group |
|---|---|---|---|
|
|
Development |
SIT |
Production |
|
|
https://dev-api.example.com |
https://sit-api.example.com |
https://api.example.com |
|
|
Employee_Dev |
Employee_SIT |
Employee_Prod |
UAT would have its own corresponding values.
4. Step 2 – Reference Variable Groups in YAML
Each deployment stage references its corresponding Variable Group.
stages:
- stage: DEV
variables:
- group: DEV-Configuration
jobs:
- job: DeployDev
steps:
- script: echo "Deploying to $(environmentName)"
- stage: SIT
variables:
- group: SIT-Configuration
jobs:
- job: DeploySIT
steps:
- script: echo "Deploying to $(environmentName)"
- stage: UAT
variables:
- group: UAT-Configuration
jobs:
- job: DeployUAT
steps:
- script: echo "Deploying to $(environmentName)"
- stage: PROD
variables:
- group: PROD-Configuration
jobs:
- job: DeployProd
steps:
- script: echo "Deploying to $(environmentName)"
This example demonstrates configuration selection. Actual deployment requires deployment tasks, and production approval should be configured separately.
5. Step 3 – Use ASP.NET Core appsettings Files
ASP.NET Core supports environment-specific configuration files.
EmployeeAPI
|
+-- appsettings.json
|
+-- appsettings.Development.json
|
+-- appsettings.SIT.json
|
+-- appsettings.UAT.json
|
+-- appsettings.Production.json
Example – appsettings.SIT.json:
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"ApiSettings": {
"BaseUrl": "https://sit-api.example.com"
}
}
Set the ASP.NET Core environment to SIT when the application starts:
ASPNETCORE_ENVIRONMENT=SIT
ASP.NET Core automatically loads appsettings.json and then appsettings.SIT.json, with the latter overriding matching values.
Important: The ASP.NET Core environment must be set in the deployed application's hosting environment, not merely in the pipeline agent.
For example, an Azure App Service deployment can set it through App Service application settings.
6. Step 4 – Store Secrets in Azure Key Vault
Sensitive values should not be hardcoded in YAML or committed to appsettings files.
Examples include database passwords, API keys, and authentication secrets.
Azure Key Vault
|
v
Key Vault-linked Variable Group
|
v
Azure DevOps Deployment Stage
|
v
Application Configuration
For example, a production Variable Group can reference secrets from a production Azure Key Vault.
The deployment process can then securely configure the application with the required values.
7. Complete CI/CD Flow
Developer commits code
|
v
Azure Repos / GitHub
|
v
CI Pipeline
- Restore
- Build
- Test
- Publish
|
v
Single Build Artifact
|
v
DEV Deployment
DEV-Configuration
|
v
SIT Deployment
SIT-Configuration
|
v
UAT Deployment
UAT-Configuration
|
v
Production Approval
|
v
PROD Deployment
PROD-Configuration
The same build artifact is promoted across all environments. Only the runtime configuration changes.
This avoids rebuilding the application for each environment.
8. Important Interview Questions
Q1. How do you manage different environment configurations in Azure DevOps?
I create separate Variable Groups for DEV, SIT, UAT and Production. Each deployment stage references the appropriate group, and sensitive values are stored in Azure Key Vault.
Q2. Do we need to build the application separately for each environment?
No. The recommended approach is to build once and deploy the same artifact across environments, applying environment-specific configuration during deployment or at runtime.
Q3. Can we use appsettings files instead of Variable Groups?
Yes. ASP.NET Core supports environment-specific appsettings files. However, Variable Groups are useful for centrally managing pipeline configuration without modifying source code.
Q4. How do you prevent developers from changing Production configuration?
Restrict permissions on Production Variable Groups and Azure Key Vault. Use Azure DevOps Environments with approvals and checks to control Production deployments.
Q5. Which configuration takes priority in ASP.NET Core?
For the standard ASP.NET Core configuration setup, environment variables override values from appsettings.json and appsettings.{Environment}.json. Command-line configuration normally has higher priority than environment variables.
Interview-ready answer
"In our Azure DevOps CI/CD process, we maintain separate Variable Groups for DEV, SIT, UAT and Production.
We build the ASP.NET Core application once and publish the artifact. During deployment, each stage uses its environment-specific Variable Group to configure database connections, API URLs and other settings.
We use ASP.NET Core appsettings files where appropriate and Azure Key Vault for sensitive values. Production deployments require approval.
This approach ensures consistent builds, secure configuration management and controlled deployments across all environments."
Key takeaway: Variable Groups manage pipeline configuration, appsettings files manage ASP.NET Core application configuration, and Azure Key Vault manages secrets.