发布 Azure Functions 和文件转换

Release Azure Functions and file transformations

我有很多 Azure Functions 项目要在 Azure 上部署。我为他们设置构建和管道。例如,这是 Azure 函数的 Release

Variables 下,我为环境定义了所有变量(一个用于开发,一个用于阶段,一个用于生产)。

只需一步即可在 Azure 上部署 Azure Functions。我想在add/replace中local.settings.json正确设置一个环境。我找不到如何配置它。

在其他项目中,如果我使用Azure App Service Deploy,则有一段File Transforms & Variable Substitution Options

如何在 Azure Functions 的发布中做同样的事情?什么是正确的策略或最佳实践?

更新与解决方案

我认为这很简单。我认为这是解决方案。在 应用程序设置 下的 应用程序和配置设置 中,我必须在该行中使用 ... 指定每个变量及其值。

我可以在此字段中键入或复制。语法是

-variableName "$(variablename)"

我使用引号是因为如果值中有任何 space(例如在连接字符串中有 Initial Catalog),DevOps 会引发错误。对于数组,我仍然使用 :.

这是我在我的 Azure Functions 管道中所做的(它是 yaml,但你会明白这个想法)。

  1. 在管道中为每个环境创建一个阶段
  2. 创建管道变量并根据范围(阶段)分配不同的值
  3. 在您的管道中创建一个配置条目(见图)并分配变量值。
  4. 在你的 Azure 函数中使用配置条目(在我的例子中我使用环境变量)

Use pipeline environment in your azure function configuration

另一种方法是使用 File Transform task to substitute the variables in local.settings.json file with pipeline variables. See here 获取更多信息。

使用文件转换任务,您不必在部署 Azure Functions 任务的应用程序设置中指定每个变量及其值。

您可以在部署 Azure Functions 任务之前添加文件转换任务。然后在管道变量中定义变量(例如KeyVaultSettings.ClientId)。

然后在文件转换中设置包或文件夹文件格式目标文件任务。见下文: