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