3

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

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Jaime
  • 5,770
  • 4
  • 23
  • 50

2 Answers2

3

You can add a new App Settings task in the pipelines,

Click + sign on the pipeline (add new task) and choose 'Azure App Service Settings' and on App Settings for the Task, add the settings you need

enter image description here

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
3

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.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107