Azure功能设置

时间:2019-07-05 10:42:03

标签: azure azure-functions

我正在尝试向azure函数添加环境变量,其中有“ local.settings.json”,但这仅用于本地开发,尽管文档并未提供任何有关如何设置设置的线索在生产中。

任何有关环境变量的文档都只说明了如何读取环境变量,但是我想写一个环境变量...

如果不存在此类文件选项,是否可以使用AZ cli设置环境变量?

2 个答案:

答案 0 :(得分:1)

有几种选择,这取决于您如何将功能部署到Azure。

Azure CLI

az functionapp config appsettings set [--ids]
                                      [--name]
                                      [--resource-group]
                                      [--settings]
                                      [--slot]
                                      [--slot-settings]
                                      [--subscription]

-settings参数包含以空格分隔的name=value对。

更多信息:https://docs.microsoft.com/en-us/cli/azure/functionapp/config/appsettings?view=azure-cli-latest#az-functionapp-config-appsettings-set

Azure功能核心工具

这会将您的功能应用程序(包括您的本地设置)发布到云端:

func azure functionapp publish <FunctionAppName> --publish-local-settings

这仅将您的本地设置发布到云中的功能应用程序:

func azure functionapp publish <FunctionAppName> --publish-settings-only

请参见https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#project-file-deployment

Azure DevOps

如果您将Azure DevOps与发布管道一起使用,则可以轻松使用Azure Function App任务:

在任务的-key value参数中以空格分隔的appSettings对的形式提供设置。

更多信息:https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-function-app?view=azure-devops

Azure门户

如Matt所述,您也可以通过配置->应用程序设置使用Azure门户进行添加/更新,但是如果您要进行自动部署,则建议您这样做。< / p>

答案 1 :(得分:0)

要将等效设置添加到Azure,您需要在“配置”下创建设置:

enter image description here

Azure函数在Azure中设置的工作方式存在一些问题/不一致,请参见this github issue,以了解更多信息,例如,如果您尝试对GetEnvironmentVariable使用连接字符串,则实际上需要将其放入作为Azure中的常规设置,例如:

enter image description here

相关问题