Azure DevOps CI/CD 部署 Web 或 Function App 更改 YAML 管道中 appsettings 中的值

标签 azure azure-devops azure-pipelines azure-web-app-service azure-function-app

最近在我们的一些部署中,关于如何自动化功能应用程序和 Web 应用程序的应用程序设置,内部存在一些困惑,并且检查周围似乎有大量令人眼花缭乱的选项,看起来它们在做大致相同的事情,但步骤不同。

我们的开发人员通常有一个提交到存储库的 appsettings.json 文件,用于测试时可能看起来像这样......

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
    }
  },
  "Values": {
    "ThingToPointTo": "http://localhost",
  }
}

当我们将其带到其他环境时,例如PROD,我们将 ThingToPointTo 更改为“https://生产服务”

我们一直在使用 Azure DevOps YAML 管道以这种方式部署和更改 AppSettings...

- task: AzureFunctionApp@1
  inputs:
    azureSubscription: 'OurAzureSubServiceConnection'
    appType: functionApp
    appName: $(azfuncappname)
    package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
    AppSettings: '-Values:ThingToPointTo "https://productionservice"'

我的问题有两个

  1. Values:ThingToPointTo 枚举到正确的设置是否正确,还是应该只是 ThingToPointTo(忽略 Values:>) ?

  2. 这是这样做的方法吗?我注意到您可以在部署之前使用 JSON 转换步骤来更改实际文件,并且还有一个名为“Azure 应用服务设置”的任务可供使用,该任务将在部署后执行此操作?

关于这个主题的文章很多,但似乎都不合适。

提前致谢!

最佳答案

Is the Values:ThingToPointTo correct for enumerating to the correct setting, or should it just be ThingToPointTo (omitting the Values:) ?

ThingToPointTo :https://productservice 可能是正确的格式。您不需要添加

例如:

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy: kevin0806'
  inputs:
    azureSubscription: '7.28-8.28'
    appType: functionApp
    appName: kevin
    appSettings: '-ThingToPointTo http://localhost'

结果:

enter image description here

Is this the way to do it? I notice there are JSON transform steps you can use to change the actual file before deploying it, and also a task called "Azure App Service Settings" available to use that will do it after deployment?

Azure App Service Settings用于在部署后更改设置。

这是模板,您可以引用:

steps:
- task: AzureRmWebAppDeployment@4
....

- task: AzureAppServiceSettings@1
  displayName: 'Azure App Service Settings: kevin0608'
  inputs:
    azureSubscription: '7.28-8.28'
    appName: kevin0608
    resourceGroupName: Kevintest
    appSettings: |
     [
        {
         "name": "ThingToPointTo",
         "value": "valueabcd",
         "slotSetting": false
        }
     
     ]

这是关于 Json Transform 的文档,你也可以引用一下。

此外,您还可以查看this ticket :

Settings from appsettings.json are not displayed in Azure App Service Configuration, but >settings defined there override values in appsettings.json

任务中的 appsettings 配置可以显示在 azure 应用服务配置中,并且可以覆盖 appsettings.json 中的值。

更新:

上面是没有嵌套变量的情况。

如果变量是嵌套值,可以遵循以下结构:

"first" : {
  "second": {
    "third" : "value"
  }
}



-first.second.third value1

如果您的应用服务是Linux,您可以使用__替换

例如- 第一__第二__第三值1

注意:变量名称匹配区分大小写

关于Azure DevOps CI/CD 部署 Web 或 Function App 更改 YAML 管道中 appsettings 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63272350/

相关文章:

json - 具有 .json 文件扩展名的 Azure 部署

c# - 未找到返回有效的 Azure 存储 URI

azure - 无法从 Azure 应用服务的源代码管理设置部署

azure - 如何将变量从管道任务传递到 terraform 任务并将其应用到我的 terraform 代码中?

azure - 如何使用Azure管道将文件上传到FTP服务器?

azure - 如果 Azure 函数超时,触发消息是否会放回 Azure 队列?

azure-devops - 使用 System.AccessToken 创建服务端点

azure - 在 yaml 中使用 if else 和 or 进行多次检查

azure-devops - 将变更集添加到版本#

azure - YAML IIS Web 部署部署组