从Azure DevOps yaml设置App Service应用程序设置

问题描述 投票:0回答:2

我们正在使用AzureRmWebAppDeployment @ 4通过yaml文件将我们的Web应用部署到Azure应用服务中。到目前为止,一切都很好。

现在我们要从yaml设置一些设置,而不是使用.json或.xml文件

当前,我们是通过Azure门户->应用程序服务->配置->应用程序设置手动完成此操作(请参见下面的屏幕截图)

我们如何从Yaml管道中以编程方式实现它?

Azure portal App Service settings

azure azure-devops yaml azure-web-sites
2个回答
0
投票

您可以在管道中添加新的App Settings task

单击[+在管道上签名(添加新任务),然后选择'Azure App Service Settings',然后在“任务的应用程序设置”上,添加所需的设置

enter image description here


0
投票

将变量直接保存在YAML文件中,尤其是与管道相同的文件中,并设置App Service的配置并不容易。确定您应该使用Azure App Service Settings任务:

- 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
        }
      ]

并且您可以使用管道(或变量组)中的变量来提供此任务或从另一个文件中读取它们,并使用以下语法在powershell任务中以编程方式设置变量:

- bash: |
    echo "##vso[task.setvariable variable=sauce]crushed tomatoes"

但是请考虑将设置保留在Azure Key Vault中。这样,您可以喂入变量组并将配置保存在安全的地方。请检查此link

© www.soinside.com 2019 - 2024. All rights reserved.