Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set App Service application setting from Azure DevOps yaml

We are using AzureRmWebAppDeployment@4 for deploying our web app into an Azure App Service via a yaml file. So far, so good.

Now we want to set few settings from yaml, rather than using a .json or .xml file

Currently we do it manually through the Azure Portal -> App Services -> Configuration -> Application Settings (see screenshot below)

How we can do it programmatically from a yaml pipeline?

Azure portal App Service settings

like image 453
Jaime Avatar asked Jan 24 '26 01:01

Jaime


1 Answers

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.

like image 129
Krzysztof Madej Avatar answered Jan 25 '26 21:01

Krzysztof Madej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!