Max Melcher

2 minute read

This will be a quick one: In this post I show you how to purge/empty an Azure CDN during an Azure DevOps deployment.

The Why

As described in this post, I use the fantastic Azure Storage Static Website feature to host this blog. SSL is a must, even for static websites - so I have to use an Azure CDN to get a free certificate. Every deployment rebuilds the entire blog and because of its static nature some artifacts can be cached for a longer duration (days!). But once I publish, I want to ensure that the most recent version is distributed and then cached in the CDN.

Deployment with Azure DevOps

I am already deploying this blog with Azure DevOps because its super fast and simple to setup - so I adjusted my build pipeline and added one more CLI task:

#purge everything
az cdn endpoint purge  -g melcherit -n melcher --profile-name melcher --content-paths "/*"

More infos about the CLI commands are available here.

My entire pipeline looks like this:

or in YAML:

steps:
- task: AzureCLI@1
  displayName: 'Azure CLI: Purge CDN'
  inputs:
    azureSubscription: '<Subscription>'

    scriptLocation: inlineScript

    inlineScript: |
     #purge everything

     call az cdn endpoint purge  -g melcherit -n melcher --profile-name melcher --content-paths "/*"

Unfortunately the Standard Microsoft CDN Profile does not allow pre-loading of assets - but with the limit of 10 load requests per minute with up to 50 paths loading this blog with 8600 files would take ~18 minutes:

And that would not make too much sense because the first load after the purge is really fast.

One small addition to my Azure DevOps pipeline - and it worked on the first try! Big like.

comments powered by Disqus