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

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.