【问题标题】:How do I run Azure Cli Script using my local Azure Cli installation如何使用本地 Azure Cli 安装运行 Azure Cli 脚本
【发布时间】:2018-08-07 12:59:06
【问题描述】:

首先我觉得这个问题很疯狂,如果这是一个非常愚蠢的问题,我很抱歉。一定很明显,因为我到处搜索都找不到答案!

我应该如何运行此 Azure 脚本来创建 Azure Function App? https://docs.microsoft.com/en-us/azure/azure-functions/scripts/functions-cli-create-serverless

#!/bin/bash

# Function app and storage account names must be unique.
storageName=mystorageaccount$RANDOM
functionAppName=myserverlessfunc$RANDOM

# Create a resource group.
az group create --name myResourceGroup --location westeurope

# Create an Azure storage account in the resource group.
az storage account create \
  --name $storageName \
  --location westeurope \
  --resource-group myResourceGroup \
  --sku Standard_LRS

# Create a serverless function app in the resource group.
az functionapp create \
  --name $functionAppName \
  --storage-account $storageName \
  --consumption-plan-location westeurope \
  --resource-group myResourceGroup

Clean up deployment

该页面提供了如何使用门户中的控制台运行它的示例,该页面还建议如果安装我拥有的 Azure CLI,我可以在本地运行它。我需要从我的本地机器上运行它,以便它可以使用参数自动化。

但是这个页面什么也没告诉我。

这个文件的扩展名应该是什么? .sh? 我使用什么命令从我的 cli 调用脚本?

我试过只输入保存为 .sh 的文件名

例如,我有 az --help,但在那里我也看不到任何东西。

【问题讨论】:

  • 您只是想执行 shell 脚本还是将脚本设置为其他 Azure CLI 命令的参数?
  • 我想我想调用 Cli 并传递脚本路径和参数,因为这可能是 CI 过程的一部分。这可能吗?
  • 您可以使用命令az vm run-command invoke。也许这就是你想要的。
  • 是的,这似乎是我需要的。谢谢!
  • 嘿@Lenny D。您是如何使用此命令运行脚本的。你能举个例子解释一下吗?

标签: azure azure-functions azure-cli


【解决方案1】:

我刚刚在我的 Mac 上测试了这个。

将脚本复制到扩展名为.sh 的文件中。我用test.sh

确保您已登录到本地 Azure CLI 实例。

然后运行: . /<path>/test.sh

【讨论】:

  • shell脚本会有权限问题。如果你想执行它,你应该授予x 权限。这个要注意。或者使用命令/bin/sh /<path>/test.sh
猜你喜欢
  • 1970-01-01
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多