简体   繁体   English

Azure DevOps CI/CD 部署 Web 或 Function 应用程序更改 Z9463F832F8B5261Z 管道中的应用程序设置中的值FBD8403F8185CABED1FCE

[英]Azure DevOps CI/CD Deploy Web or Function App changing the values in appsettings in YAML Pipelines

There has been some confusion internally around how to automate appsettings for Function Apps and Web Apps recently with some of our deployments, and checking around there appears to be a bewildering amount of options that look like they are doing roughly the same thing, but in different steps.最近在我们的一些部署中,关于如何自动化 Function 应用程序和 Web 应用程序的应用程序设置在内部存在一些混乱,并且检查那里似乎有大量令人眼花缭乱的选项,看起来他们在做大致相同的事情,但在不同的地方脚步。

Our developers usually have an appsettings.json file they commit to the repo that might look something like this for their testing...我们的开发人员通常有一个 appsettings.json 文件,他们提交给他们的测试可能看起来像这样的 repo...

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

When we take that to other environment eg PROD, we change the ThingToPointTo to something like "https://productionservice"当我们将其带到其他环境(例如 PROD)时,我们将ThingToPointTo更改为“https://productionservice”

We have been using the Azure DevOps YAML pipelines to deploy and change the AppSettings in this way...我们一直在使用 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"'

My question is 2-fold我的问题是2倍

  1. Is the Values:ThingToPointTo correct for enumerating to the correct setting, or should it just be ThingToPointTo (omitting the Values: )? Values:ThingToPointTo是否正确枚举到正确的设置,还是应该只是ThingToPointTo (省略Values: )?

  2. 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?我注意到有 JSON 转换步骤可用于在部署之前更改实际文件,还有一个名为“Azure App Service Settings”的任务可以在部署后使用?

There are so many articles on the subject of this, but none seem to fit.有很多关于这个主题的文章,但似乎没有一个适合。

Thanks in advance!提前致谢!

Is the Values:ThingToPointTo correct for enumerating to the correct setting, or should it just be ThingToPointTo (omitting the Values:)? Values:ThingToPointTo 是否正确枚举到正确的设置,还是应该只是 ThingToPointTo(省略 Values:)?

The ThingToPointTo :https://productionservice could be the correct format. ThingToPointTo :https://productionservice可能是正确的格式。 You don't need to add values .您不需要添加values

For example:例如:

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

Result:结果:

在此处输入图像描述

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?我注意到有 JSON 转换步骤可用于在部署之前更改实际文件,还有一个名为“Azure App Service Settings”的任务可以在部署后使用?

The Azure App Service Settings is used to change the setting after deployment. Azure App Service Settings用于在部署后更改设置。

Here is the template, you could refer to it:这是模板,您可以参考:

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

Here is a doc about Json Transform , you could also refer to it.这是一个关于Json Transform的文档,您也可以参考它。

In addition, you could check this ticket :此外,您可以查看这张票

Settings from appsettings.json are not displayed in Azure App Service Configuration, but >settings defined there override values in appsettings.json来自 appsettings.json 的设置不会显示在 Azure 应用服务配置中,但 > 在那里定义的设置会覆盖 appsettings.json 中的值

The appsettings configuration in the task could show in the azure app service configuration, and it could override the value in appsettings.json.任务中的 appsettings 配置可以显示在 azure 应用服务配置中,它可以覆盖 appsettings.json 中的值。

Update:更新:

The above is the case without nested variables.以上是没有嵌套变量的情况。

If the variable is nested values, you can follow the following structure:如果变量是嵌套值,可以遵循以下结构:

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



-first.second.third value1

If your app service is linux, you could use __ to replace .如果您的应用服务是 linux,您可以使用__替换.

eg - first__second__third value1例如- first__second__third value1

Note: Variable name matching is case-sensitive注意:变量名匹配区分大小写

Thanks to @Kevin Lu-MSFT for talking through those options with me感谢@Kevin Lu-MSFT 与我讨论这些选项

We found that for webapps that have nested values...eg我们发现对于具有嵌套值的 webapps...例如

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

...that the AppSettings in the AZDO YAML pipeline would indeed be... ... AZDO YAML 管道中的 AppSettings 确实是...

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

THIS IS DIFFERENT IT SEEMS FOR FUNCTION APPS!这似乎与 FUNCTION 应用程序不同!

If you have "Values" in the JSON you DON'T use Values: to enumerate...!...如果您在 JSON 中有“值”,则不要使用 Values: 来枚举...!...

For example...例如...

{
  "Values": {
    "ThingToPointTo": "http://localhost",
  }
}

...ends up being... ...最终成为...

AppSettings: '-ThingToPointTo "https://productionservice"'

There seems to be a double-standard with Function Apps. Function Apps 似乎存在双重标准。 So beware (Most of this was completed using a .Net Core and Windows setup where applicable in Azure)所以请注意(其中大部分是使用 .Net 核心和 Windows 设置完成的(如果适用于 Azure)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署 Azure function 应用程序的应用程序设置使用 Azure Devops 和 Z65F603ZDevops 和 Z65F6036BFC967981CE2333036BFC96798CE23 - Deploy Appsettings for Azure function app using Azure Devops and Yaml and Variable group 使用 Azure DevOps CI/CD 管道自动部署 ADF 管道 - Automated Deployment of ADF Pipelines using Azure DevOps CI/CD Pipelines CI/CD 到 azure devops 中的 Angular Web 应用程序成功但没有任何反应 - CI/CD to angular web app in azure devops succeeded but nothing happen CI-CD Azure devops 用于 function 应用程序部署 - CI-CD Azure devops for function app deployment 如何通过 CI/CD 管道将 Azure 函数部署到函数应用中? - How to deploy an Azure function into a function app through a CI/CD pipeline? Gitlab CI/CD 部署到 Azure Web 服务 - Gitlab CI/CD deploy to Azure Web Service 如何通过 Azure Devops CI/CD 使用单个 arm 模板部署多个逻辑应用程序? - How to deploy multiple logic app with single arm template via Azure Devops CI/CD? 在 Azure CI/CD 管道中使用 npm 工作区来构建 React Web 应用程序? - Using npm workspaces in Azure CI/CD pipelines to build React web app? 使用 Azure Devops yaml 管道部署到本地服务器 - Using Azure Devops yaml pipelines to deploy to on-prem servers 使用 Devops CI/CD 将 Django Web 应用程序部署到 Azure 应用程序服务上 - Deploying Django Web App using Devops CI/CD onto Azure App Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM