AzureBlob File Copy - clean up $web

Viewed 986

I configured an Azure Release Pipeline for my Angular 8 App which copies the compiled app data to $web in an Azure Blob Storage Account. It overrides existing files, which is fine. But some of the compiled files that are created by the Angular compiler are named differently for every compilation. This leads to an increasing amount of obsolete files in $web.

The AzureBlob File Copy task does not offer an option to initially clear/clean up $web.

How can I achieve the initial cleanup of $web?

3 Answers

You can use Azure CLI task to invoke the az cli commands az storage blob delete-batch to clean up the container $web before running the Azure File Copy task. The sample code is as below:

az storage blob delete-batch -s mycontainer --account-name mystorageaccount --account-key mystorageaccountkey

enter image description here

Azure DevOps pipeline task has issues identifying the container with name "$Web" which is created by default when creating a static website in Azure Storage.

I used an Azure CLI task and wrote the following powershell script to achieve this:

$connectionContext = (Get-AzStorageAccount -ResourceGroupName <Your resource group name> -AccountName <Your storage account name>).Context

$Container = Get-AzStorageContainer -Context $connectionContext -Name '$web'

write-host  clearing files in container $Container.Name

Get-AzStorageBlob -Container $Container.Name -Context $connectionContext | ForEach-Object {
    write-host removing $_.Name
    $_ | Remove-AzStorageBlob
}

If you are using a Windows based agent with powershell inline script, change double quotes to single.

az storage blob delete-batch --account-name <account_name> --source '$web'
Related