【问题标题】:is there any way to create the AzureBlob containers and direcories inside a storage account using azure cli method?有什么方法可以使用 azure cli 方法在存储帐户中创建 AzureBlob 容器和目录?
【发布时间】:2022-01-04 18:31:19
【问题描述】:
仅在给定路径不存在的情况下,寻找 azurecli 任务或 arm 模板以在现有 Datalake 存储帐户 gen2 内的 blob 中创建 blob 和目录。希望将此任务自动化到 Azurepipeline ,我可以首先在存储帐户中验证并创建目录路径,如果不存在则创建它。然后我有另一个 azure cli 任务来设置其中的权限。因此,如果不存在,则寻找最初实现的第一个任务以创建 blob 和目录路径。
【问题讨论】:
标签:
azure-pipelines
azure-storage
azure-data-lake
azure-cli
azure-data-lake-gen2
【解决方案1】:
您可以在 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