This post was originally published on Geert van der Cruijsen's blog at Created an open source VSTS build & release task for Azure Web App Virtual File System.
I’ve created a new VSTS Build & Release task to help you interact with the (VFS) Virtual File System API (Part of KUDU API of your Azure Web App). Currently this task can only be used to delete specific files or directories from the web app during your build or release workflow. It will be updated in the near future to also be able to list files or to upload / download files through the VFS API
The reason i made this task was that i needed it at my current customer. We’re deploying our custom solution to a Sitecore website running on Azure web apps using MSDeploy. The deployment consists of 2 parts: an install of the out-of-the-box Sitecore installation and the deployment of our customisations. When deploying new versions we want to keep the Sitecore installation and MSDeploy will update most of our customisations. Some customisations however create artifacts that stay on the server and aren’t in control of the MSDeploy package that can cause errors on our web application. This new VSTS Build / Release task can help you delete these files. In the future this task will be updated with other functionality of the VFS API such as listing, uploading or downloading files.
Let’s have a look how to use this task and how it works under the hood.
Using the task
So how do we delete files using this task? (Note: if you want to delete all files within a web app before doing a MSDeploy it’s better to check the “Remove Additional Files at Destination” checkbox in the advanced group of the Azure Web deploy task. This task is made to delete specific files or folders
Using the task is pretty simple. install the task from the marketplace, add it to your workflow and fill in the following fields:
- Azure subscription (select your Azure RM connection)
- App Service Name (select the web app you want to delete files at)
- File URL (enter the file url within the wwwroot that you want to delete. use path ending on / for directories)
optionally add the following parameters
- Recursive delete (Default ON if you select a directory also delete all files and directories in this directory)
- Skip non existing path (If file or directory does not exist any more do not throw error but continue)
- Allow self signed certificates (only use this when you you run in an ASE and have your own certificates)
- Alternative kudu URL (When running in ASE and the SCM url is different fill in the exact url here)
The task under the hood
Under the hood this task uses the VFS API. The full source can be found on my github but i’ll point out the main powershell functions.
The Remove-FileFromWebApp function is the core function that is being called from the build task. This function will check if the file path is a directory or a file. If it’s a directory it will check if the recursive delete is on. if this is the case it will call the function recursively to delete each file within the directory including subdirectories.
After that we’ll construct the VFS API Url we’re going to call to delete the file. Remaining 2 blocks of code. 1 doing the actual call of the API through Invoke-RestMethod but before that we check if the advanced option “Allow self signed certificates” is on and if this is on we’ll create a new policy first and add before we do the actual call.
This release is the first release of this task. Code to list files from the API is already used to do the recursion and the API also supports Uploading and downloading files so i’ll add tasks for that as well in the near future. If you have any feedback or feature requests just let me know in a comment below or contact me on my twitter
Happy Coding, Building & Releasing
Geert van der Cruijsen
The post Created an open source VSTS build & release task for Azure Web App Virtual File System appeared first on Mobile First Cloud First.