Timeout issues deploying to a continuous web job

Some time ago I wrote about how to create a YAML Azure DevOps pipeline to deploy a .NET framework v1 webjob.

In this post, I will speak to a problem I had to troubleshoot. The Azure Pipelines agent timing out because it took over an hour to deploy to a continuous web job.

My problem was that the continuous webjob had the binaries locked and therefore I could not upload new binaries while the webjob was running.

The solution was relatively simple.

Use the App Service Manage task to stop the webjob before deploying, then deploy, then start the webjob.

The pipeline

First, I will assume some variables defined in the pipeline like this.

variables:
  SubscriptionServiceConnection: 'your azure service connection name'
  WebjobAppName: 'the name of your webjob'

Then, you’ll want to use the AzureAppServiceManage@0 to stop the web job.

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: '$(SubscriptionServiceConnection)'
    Action: 'Stop Azure App Service'
    WebAppName: '$(WebjobAppName)'

Notice: The Microsoft documentation has a mistake on it. The action parameter is case sensitive. Ensure that the value matches Stop Azure App Service.

Next, you can deploy the webjob using the AzureRmWebAppDeployment@4 task.

- task: AzureRmWebAppDeployment@4
  displayName: 'Deploy WebJob'
  inputs:
    azureSubscription: '$(SubscriptionServiceConnection)'
    WebAppName: $(WebjobAppName)
    packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
    enableCustomDeployment: true
    ExcludeFilesFromAppDataFlag: false

Lastly, you can start the webjob again.

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: '$(SubscriptionServiceConnection)'
    Action: 'Start Azure App Service'
    WebAppName: '$(WebjobAppName)'

Notice: Similar to the warning before, the action is case sensitive. Ensure that the value matches Start Azure App Service.