有没有办法使用azurecli方法在存储帐户内创建AzureBlob容器和目录



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

您可以在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

最新更新