英文:
How to delete files in Azure Blob Storage by date using AzureCLI?
问题
I'm trying to use the --if-unmodified-since
flag on the delete-batch
command to delete files, but Azure throws an error on my inline script.
我尝试在delete-batch
命令上使用--if-unmodified-since
标志来删除文件,但Azure在我的内联脚本上抛出错误。
I'm doing this in Azure DevOps on an Ubuntu VM using an azure-pipelines.yml file.
我在Ubuntu虚拟机上使用azure-pipelines.yml文件在Azure DevOps中进行此操作。
This command:
这个命令:
- task: AzureCLI@2
displayName: Delete old files
inputs:
azureSubscription: 'Main subscription (xxx-xxx-xxx)'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az storage blob delete-batch -s $web --account-name mystorage --if-unmodified-since `date -d "1 days ago" '+%Y-%m-%dT%H:%MZ'`
Returns an Incomplete string token
error, pointing at the end of the inline script.
返回一个不完整的字符串标记
错误,指向内联脚本的末尾。
英文:
I'm trying to use the --if-unmodified-since
flag on the delete-batch
command to delete files, but Azure throws an error on my inline script.
I'm doing this in Azure DevOps on an Ubuntu VM using an azure-pipelines.yml file.
This command:
- task: AzureCLI@2
displayName: Delete old files
inputs:
azureSubscription: 'Main subscription (xxx-xxx-xxx)'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
az storage blob delete-batch -s $web --account-name mystorage --if-unmodified-since `date -d "1 days ago" '+%Y-%m-%dT%H:%MZ'`
Returns an Incomplete string token
error, pointing at the end of the inline script.
答案1
得分: 3
Backtick (`) 用于在 PowerShell 中转义字符,所以我认为更容易使用 $( command ) 来执行嵌套命令 [date -d "1 days ago" '+%Y-%m-%dT%H:%MZ' 是一个 Linux 命令]
这里是对我有效的任务
- 任务:AzureCLI@2
输入:
azureSubscription: 'Visual Studio 专业订阅(xxxxxx)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: 'az storage blob delete-batch -s images --account-name mystorage --if-unmodified-since $(date -d "5 days ago" '+%Y-%m-%dT%H:%MZ')'
英文:
Backtick (`) is used for escaping characters in powershell, so I think it is easier to use $( command ) to execute nested commands [date -d "1 days ago" '+%Y-%m-%dT%H:%MZ' is a linux command]
Here the task, which worked for me
- task: AzureCLI@2
inputs:
azureSubscription: 'Visual Studio Professional Subscription(xxxxxx)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: 'az storage blob delete-batch -s images --account-name mystorage --if-unmodified-since $(date -d `"5 days ago`" ''+%Y-%m-%dT%H:%MZ'')'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论