Forum Discussion
jbadam0312
Sep 26, 2023Copper Contributor
To write .yml file to deploy .net application in Azure Virtual Machine
Hi Team, I am planning to write .yml file to deploy the web app in Azure virtual Machine with different environments(Like Dev, QA , UAT and Prod). Here I want to use variable group as well, I ca...
Kidd_Ip
Jul 20, 2025MVP
Take this:
Folder Structure Suggestion:
/azure-pipelines
├── azure-pipelines.yml
├── templates/
│ └── deploy-template.yml
└── vars/
├── vars-dev.yml
├── vars-qa.yml
├── vars-uat.yml
└── vars-prod.yml
Sample Variable Group Template (vars/vars-dev.yml)
variables:
environmentName: 'Dev'
webAppName: 'myapp-dev'
vmGroup: 'vm-dev-group'
configFilePath: 'Configs/web.dev.config'
Repeat similarly for QA, UAT, and Prod.
Main Pipeline (azure-pipelines.yml)
trigger:
branches:
include:
- main
stages:
- stage: DeployDev
displayName: 'Deploy to Dev'
jobs:
- template: templates/deploy-template.yml
parameters:
env: 'dev'
variableFile: 'vars/vars-dev.yml'
- stage: DeployQA
displayName: 'Deploy to QA'
jobs:
- template: templates/deploy-template.yml
parameters:
env: 'qa'
variableFile: 'vars/vars-qa.yml'
Deployment Template (templates/deploy-template.yml)
parameters:
env: ''
variableFile: ''
jobs:
- job: DeployJob
displayName: 'Deploy to ${{ parameters.env }}'
variables:
- template: ${{ parameters.variableFile }}
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'Your-Service-Connection'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
Write-Host "Deploying to $env:environmentName"
# Replace web.config based on environment
Copy-Item $env:configFilePath -Destination '$(Build.ArtifactStagingDirectory)/web.config' -Force
# Add your deployment logic here (e.g., Web Deploy, PowerShell Remoting)