Azure-pipelines-tasks: Can Azure Web App Deployment have an option to stop/start web app?

Created on 13 Feb 2016  ·  14Comments  ·  Source: microsoft/azure-pipelines-tasks

Currently we're getting an error during the deployment like this:

Web Deploy cannot modify the file 'Microsoft.CodeAnalysis.CSharp.dll' on the destination because it is locked by an external process

if don't stop and the start the website manually.

Can you instead just add an option to do this automatically?

Most helpful comment

@frourke , We recently added Azure App Service Manage Task (Preview) to manage Start, Stop, Restart and swap slots in Azure App Service. This task is available in most of the regions and will be available to all the regions soon.

All 14 comments

https://github.com/Azure/azure-powershell/issues/669
Currently the command let it'self doesn't support it.
We don't directly use msdeploy now, however this will change soon.
Then we should be able to achieve this independent of that issue

I think as a mid-term workaround, you could call powershell twice yourselves, and then once it's supported 'natively', drop this workaround.

We don't want to hack around this :) Work to switch to msdeploy is near though

I've run into this as well. Here's what we're doing as a work around. We run an Azure Resource Manager powershell script with something like the following code as Manage-WebApps.ps1:

Param(
    [Parameter(Mandatory = $true, ParameterSetName = 'Start')]
    [Parameter(Mandatory = $true, ParameterSetName = 'Stop')]
    [string]$Environment,

    [Parameter(Mandatory = $true, ParameterSetName = 'Start')]
    [switch]$Start,

    [Parameter(Mandatory = $true, ParameterSetName = 'Stop')]
    [switch]$Stop
)

$ResourceGroup = "--Your Resource Group--"
$appsToManage = @("app1", "app2", "appN")

ForEach ($app in $appsToManage) {
    $appName = "$Environment-$app"
    if ($Start) {
        Start-AzureRmWebApp -ResourceGroupName $ResourceGroup -Name $appName | Out-Null
        Write-Host "Started web app '$appName'"
    }
    if ($Stop) {
        Stop-AzureRmWebApp -ResourceGroupName $ResourceGroup -Name $appName | Out-Null
        Write-Host "Stopped web app '$appName'"
    }
}

We'll run this at the beginning of the release:

Manage-WebApps.ps1 -Stop -Environment dev

And this at the end:

Manage-WebApps.ps1 -Start -Environment dev

What other work-arounds have people found?

Yeah, I don't see a better workaround than using Start/Stop-RmWebApp.

I have developed a PowerShell script “Stop-WebSite.ps1” and run the below command to stop the Azure Web App from script.

Stop-AzureRmWebApp -ResourceGroupName $ResourceGroup -Name $Name
*
But now it is throwing an error “
Run Login-AzureRmAccount to login*”. So is there any way to login programmatically by PowerShell command.

image
Thanks in advance
Nabhendu Das

Task doesn't support ARM authentication yet.
You best bet would be to use "Azure powershell" task.
Select "Azure Resource Manager" as connected type and run the script.
and also try setting "DonotDelete" flag in the azure web app task as a workaround. I heard from few people that it worked.

After attempting the "DonotDelete" flag in the web app deployment task, I get the following warning:

Cannot update deployment status for _webappname_ - {"Message":"Deployment with id '54b6b36ba42559b6553782de67834afe4c3c98e7' exists"}

The site was locked up for a period of time (maybe about a minute). Eventually it came back on line.

Essentially that means deployment was triggered more than once for the same commit.
However, it will be changed in current sprint, so that it would consider other unique Id's instead.

Essentially you need to stop - deploy - restart .

You have many options to do it but to more easy would be:

1- Extention: Azure App Services - Start and Stop
you can try the extension "Azure App Services - Start and Stop" https://marketplace.visualstudio.com/items?itemName=rbengtsson.appservices-start-stop

2- AzureCLI task
From the build or Deployment windows Add am Azure CLI task (currently in Preview)

Add one before the Deployment task
with Inline script:

azure webapp stop --resource-group NAME_OF_YOUR_RESOURCE_GROUP --name WEBAPP_NAME

Add another one after the Deployment task
with Inline script:

azure webapp start --resource-group NAME_OF_YOUR_RESOURCE_GROUP --name WEBAPP_NAME

I hope that help.

Careful with "azure webapp stop|start" if you are working with slots.
Currently this command ignores the --slot xxx and always uses the production slot.

@frourke , We recently added Azure App Service Manage Task (Preview) to manage Start, Stop, Restart and swap slots in Azure App Service. This task is available in most of the regions and will be available to all the regions soon.

Has the status of this changed or are we still suggested to use Azure App Service Manage Task to Stop, then Azure App Service Deployto deploy, then Azure App Service Manage Task to Start again

@mikemaat , there is no change. As you said, the recommended way is to use Manage task for start/stop action and Deploy task for deployment.

Was this page helpful?
0 / 5 - 0 ratings