有什么方法可以使用 azure cli 方法在存储帐户中创建 AzureBlob 容器和目录?

is there any way to create the AzureBlob containers and direcories inside a storage account using azure cli method?

正在寻找 azurecli 任务或 arm 模板以在现有 Datalake 存储帐户 gen2 内的 blob 中创建 blob 和目录,前提是给定路径不存在。希望将此任务自动化到 Azurepipeline,我可以首先在存储帐户中验证和创建目录路径,如果不存在则创建它。然后我有另一个 azure cli 任务来设置它们的权限。所以我寻找第一个任务,如果它不存在,首先要创建 blob 和目录路径。

您可以在 Azure CLI 任务中使用 powershell 脚本来检查容器或目录是否存在并创建它们

而内联脚本可以如下:

$existing_container = (az storage container exists --account-name mystorageccount --name mycontainer  --auth-mode login | ConvertFrom-Json).exists
$existing_directory = (az storage blob directory exists  --directory-path directoryName --account-name mystorageccount --container-name mycontainer  --auth-mode login | ConvertFrom-Json).exists
if (!$existing_container)
                   az storage container create --account-name mystorageccount --name mycontainer  --auth-mode login
if (!$existing_directory)
                   az storage blob directory create --account-name mystorageccount --container-name mycontainer  --directory-path directoryName --auth-mode login