我可以使用 Azure 门户创建函数应用和函数,并将输出绑定添加到消息队列。例如,通过使用函数下的集成选项,我可以添加一个新的输出,在本例中是一个消息队列:
添加新消息队列后,function.json 文件将使用门户中的新绑定进行更新。
前:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
后:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
},
{
"type": "queue",
"name": "myQueueItem",
"queueName": "myoutputqueue",
"connection": "AzureWebJobsStorage",
"direction": "out"
}
]
}
现在我可以在我的 Azure 函数中引用消息队列。
在门户中很容易做到。但是,如果它尚不存在,我想通过构建管道创建队列存储(或任何其他类型)。我认为这在发布定义中最有意义,但我无法确定如何检测帐户和队列是否已经存在,或者如果不存在则创建它们。我想我可以通过 Azure Powershell 脚本发布定义任务使用 Azure Powershell 命令,并使用此处描述的命令:
使用 Azure PowerShell 执行 Azure 队列存储操作
但是当我尝试在 Azure Powershell CLI 中手动使用“Get-AzureStorageAccount”来查看存储帐户是否存在时,我收到一条错误消息,指出“Get-AzureStorageAccount”不是有效的命令行开关。有没有办法通过 CI/CD 管道管理 Azure 函数存储和绑定?