I was recently setting up a deployment in Visual Studio Team Services to a site that uses Cloudflare. One of the requirements was to clear the Cloudflare CDN cache as part of the release as content was cached on Cloudflare that could change after the application has deployed.
This is a "note to self" to ensure I remember the steps needed to clear the Cloudflare cache as part of a release in Visual Studio Team Services:
Get the zone ID from Cloudflare
Get the Global API key from Cloudflare (My Profile > API Keys > Global API get):
Get the zone ID from the Cloudflare API for my zone. For this the following CURL command works:
curl -X GET "https://api.cloudflare.com/client/v4/zones?name=[cloudflare.zone.name]&status=active" \ -H "X-Auth-Email: "[[email protected]]" \ -H "X-Auth-Key: "[cloudflare.api.key]" \ -H "Content-Type: application/json"
The id in the result is the zone ID of the named Cloudflare zone.
Adding to the Visual Studio Team Services release
Next up we need to plug this into the Visual Studio Team Services release pipeline. Edit the release pipeline and add an agentless phase. Add an "Invoke REST API" task as shown below:
The config above also requires us to click the "Manage" link and set up a generic endpoint to the Cloudflare API. Once in the Services > Endpoints UI click "New Service Endpoint" and select Generic. Once there configure as follows:
Save the endpoint, return to the release pipeline and select "Cloudflare - purge cache" as the generic endpoint (as shown above).
Finally save the release definition and verify that the Cloudflare CDN cache gets cleared when the Visual Studio Team Services release is performed.
It turned out that clearing the Cloudflare cache as part of a release in Visual Studio Team Services could be done out the box using standard configuration. I like Visual Studio Team Services and Cloudflare even more after having done this!