发布 azure 函数 - 你能创建一个模板 json 资源文件吗

publishing azure function - can you create a template json resource file

我有一个需要自动部署脚本的 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"
        }

这段代码工作正常,但我不想再使用动态函数名了。我想要完成的是以下内容:

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

试试这个:

$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