It won't be easy to keep variables directly in YAML file especially in the same file as pipeline and set configuration of App Service. For sure you should use Azure App Service Settings task:
- task: AzureAppServiceSettings@0
displayName: Azure App Service Settings
inputs:
azureSubscription: $(azureSubscription)
appName: $(WebApp_Name)
# To deploy the settings on a slot, provide slot name as below. By default, the settings would be applied to the actual Web App (Production slot)
# slotName: staging
appSettings: |
[
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "$(Key)",
"slotSetting": false
},
{
"name": "MYSQL_DATABASE_NAME",
"value": "$(DB_Name)",
"slotSetting": false
}
]
generalSettings: |
[
{
"name": "WEBAPP_NAME",
"value": "$(WebApp_Name)",
"slotSetting": false
},
{
"name": "WEBAPP_PLAN_NAME",
"value": "$(WebApp_PlanName)",
"slotSetting": false
}
]
connectionStrings: |
[
{
"name": "MysqlCredentials",
"value": "$(MySQl_ConnectionString)",
"type": "MySql",
"slotSetting": false
}
]
And you can use variables from pipeline (or variable group) to feed this task or read them from another file and set variables programitacally in powershell task using this syntax:
- bash: |
echo "##vso[task.setvariable variable=sauce]crushed tomatoes"
But please consider keeping your settings in Azure Key Vault. In this way you can feed your variable group and keep configuration in safe place. Please check this link.