Search code examples
powershellazureazure-web-app-serviceoctopus-deploy

How to delete a folder on an Azure App Service website using Octopus Deploy


I am setting up an automated deployment project for a Sitecore website using TeamCity and Octopus Deploy (v. 3.3.6).

Before deploying to the App Service using a "Deploy an Azure Web App" step, I would like to delete one folder on that site (/site/wwwroot/App_Config/Include or D:\home\site\wwwroot\App_Config\Include).

Is there a built-in mechanism in Octopus to do this? I have tried using a Powershell script, but that runs on the server, not on Azure. Is there a way to run a Powershell script on Azure while deploying? Or can I use the "Run an Azure Powershell Script" to do file manipulations on an App Service website without having to authenticate (since Octopus is doing the authentication)?

Or are there any other/better solutions to solve this without having to save credentials in a file on the Build Server?

I would prefer not to use FTP for this, if at all possible.


Solution

  • I would do this:

    1. Create a on-demand webjob in Azure and upload a powershell script that can clean up the folder to your Webapp. Try to keep this ps script simple, use base cmdlet commands, not all ps modules would run in azure. How: https://blogs.msdn.microsoft.com/nicktrog/2014/01/22/running-powershell-web-jobs-on-azure-websites/

    2. You still need your teamcity or octopus to run a powershell line to kick off the webjob. With that, the work load is not on octopus server anymore but you still need the same azure authentication process for the powershell line. How: http://www.nullfactory.net/2015/05/start-azure-webjobs-on-demand/

    "Run an Azure Powershell Script" in octopus helps you load the Azure Powershell module and do the Azure-Subscription trick, so you don't need to include the library within the script or re-authenticate. It still runs locally but step #2 fits this well.

    Hope this can help you.