azure - 发布azure函数-您可以创建模板json资源文件吗

标签 azure powershell azure-functions

我有一个需要自动部署脚本的 Azure 函数。目前,Powershell 脚本中有一行如下所示:

#create resources defined in JSON - 
az deployment group create --resource-group TESTGROUP --template-file resources.json

这是资源文件中函数名称的内容:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "functionapp_name": {
            "defaultValue": "[concat('widgets-',uniqueString(resourceGroup().id))]",
            "type": "String"
        }

这段代码工作正常,但我不想再使用动态函数名称。我想要完成的任务如下:

  • 如果 local.settings.json 存在,那么我想通过开发者的机器主机名来调用函数名
  • 如果没有 local.settings.json 文件,那么我知道这是针对产品环境的,所以我想使用不同的值。

有没有简单的方法可以做到这一点?

最佳答案

试试这个:

$file = 'path\to\local.settings.json'
$functionAppName = 'nameToGiveYourFunctionAppIfInProd'

#If the file exists, use dev machine hostname.
if (Test-Path -Path $file -PathType Leaf) {
     $functionAppName = [System.NET.DNS]::GetHostByName('').HostName
}

#Now run your az deployment script and pass the funcAppName as parameter

#create resources defined in JSON - 

az deployment group create --resource-group TESTGROUP --template-file resources.json --parameters functionapp_name=$functionAppName

关于azure - 发布azure函数-您可以创建模板json资源文件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68105622/

相关文章:

azure - 是否可以在Azure Function中监听UDP

c++ - 如何以编程方式关闭 Windows 中打开的文件/应用程序?

powershell - PowerShell脚本:按对象大小(以MB为单位)排序

Angular 5 调用 Azure AD protected Web API 导致 CORS

Azure 自动化无法将参数传递给 VM 内的 powershell 脚本

powershell - 如何使用 powershell 对 CSV 列重新排序?

Azure函数返回错误: No job functions found.尝试将作业类和方法公开

c# - MessageLockLostException : The lock supplied is invalid. 锁已过期,或者消息已从队列中删除

azure - 关于 Azure 表二级索引

azure - 对 Azure 托管和计费感到困惑吗?