如何使用AzureCLI按日期删除Azure Blob Storage中的文件?

huangapple go评论64阅读模式
英文:

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.

如何使用AzureCLI按日期删除Azure Blob Storage中的文件?

答案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'')'

huangapple
  • 本文由 发表于 2020年1月7日 02:25:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/59617090.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定