question

cvashm avatar image
2 Votes"
cvashm asked RafalStankowskiRST-5496 commented

Sporadically not able to deploy code to AppService even ARM deployment has finished

We are, sporadically, seeing problems that we cannot deploy code to our AppService, even though that the ARM deployment of the AppService has finished. This is only a problem the first time when deploying an AppService - retrying the pipeline that fails with the deployment has fixed the problem so far. Once the AppService has been deployed (ARM + code) the first time, we have not seen the problem afterwards. But as we are deploying a lot of new services on a daily basis in our CI/CD pipelines for testing purposes, this causes some noise.

And we are using the following Azure DevOps pipeline task for the deployment (https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/AzureWebAppV1):

  • task: AzureWebApp@1
    displayName: Azure WebApp Deployment
    inputs:
    azureSubscription: 00000000-0000-0000-0000-000000000000
    appType: webApp
    appName: anonymizedAppServiceName
    package: anonymizedAppServiceName.zip
    deploymentMethod: runFromPackage

from which we get the following error:

"Resource 'anonymizedAppServiceName' doesn't exist. Resource should exist before deployment."

We have in one concrete case observed the following timings:

ARM Deployment: 16:13:52 -> 16:15:01
Code Deployment: 16:15:31 -> 16:15:47

But looking at the activity log for the WebApp, we are seeing activity even after the ARM deployment has finished:

"Update website": 16:14:18
"Update website": 16:14:40
"Update website": 16:24:23

Are we doing something wrong here? It seems that the AppService is not fully provisioned and ready for code deployment, even if the ARM deployment has completed?

azure-webapps
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@cvationshm, Thanks for posting this good question with a detailed description.

While I'm checking on this issue internally.

II understand the issue occurs only the first time, kindly review the package folder and see if this isolates the issue - The zip file (artifact created by build pipeline in DevOps) was being deployed directly and was not getting extracted or mounted as run from package. This happened due to the missing wildcard selection for zip file (**/*.zip) in the artifact directory.
If the wild card selection for zip/war file is not present, the CD pipeline treats the target folder as the artifact.

Set the wildcard for zip file /select that specific artifact and see how the deployment goes.

1 Vote 1 ·

Sorry, I was a little confused on this one. With the package folder, did you mean "https://anonymizedAppServiceName.scm.azurewebsites.net/api/vfs/data/SitePackages/"?

0 Votes 0 ·

@ajkuma-MSFT I'm seeing this as well, just ran into it 10m ago. In our case, we are deploying with Terraform and after terraform apply completed, we attempt a code deploy to the provisioned function app.

That code deploy task triggered ~30s after the terraform apply completed successfully, and claimed the function app did not exist. We were able to immediately pull up that app in the Azure Portal, so something is amiss. I looked at the task and see it's listing all resources of type Microsoft.Web/Sites so my guess is something is amiss with caching on the REST API responses, and it's not getting the most up-to-date results intermittently.

1 Vote 1 ·

We are observing a similar situations many times, not with terraform but with arm templates.
The scenario is that we provision function app in jobA and 3 minutes later we are trying to deploy the code in jobB.
And from time to time it states:

[GET]https://management.azure.com/subscriptions/ff74ff0e-119d-4627-9d0c-c3b815b000dc/resources?$filter=resourceType EQ 'Microsoft.Web%252FSites' AND name EQ 'GOOD-FUNCTION-NAME'&api-version=2016-07-01
Deployment Failed with Error: Error: Resource 'GOOD-FUNCTION-NAME' doesn't exist. Resource should exist before deployment.

When we retry it then it deploys with a success.



0 Votes 0 ·

First time error even the resource name is correct and it exists on resource group:

[debug]Processed: ##vso[task.issue type=error;]Error: Resource 'GOOD-FUNCTION-NAME' doesn't exist. Resource should exist before deployment.

(node:1860) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getApplicationURL' of undefined
at WindowsWebAppWebDeployProvider.<anonymous> (D:\a_tasks\AzureRmWebAppDeployment_497d490f-eea7-4f2b-ab94-48d9c1acdcb1\4.184.4\deploymentProvider\AzureRmWebAppDeploymentProvider.js:54:73)
at Generator.next (<anonymous>)
at D:\a_tasks\AzureRmWebAppDeployment_497d490f-eea7-4f2b-ab94-48d9c1acdcb1\4.184.4\deploymentProvider\AzureRmWebAppDeploymentProvider.js:8:71
at new Promise (<anonymous>)
at __awaiter (D:\a_tasks\AzureRmWebAppDeployment_497d490f-eea7-4f2b-ab94-48d9c1acdcb1\4.184.4\deploymentProvider\AzureRmWebAppDeploymentProvider.js:4:12)

Azure App Service deploy Version : 4.184.4

0 Votes 0 ·

As a side note, Resource Manager optimizes deployment by creating resources in parallel. If one resource must be deployed after another resource, you need to use DependsOn element in your template.
Example -If you haven't specified that the web app depends on the App Service Plan, Resource Manager creates both resources at the same time. The error stating that the App Service Plan resource can't be found, because it doesn't exist yet when attempting to set a property on the web app.

0 Votes 0 ·

It is my belief that we have configured dependsOn correctly between the resources. I have tried to export a dependency chart among the service, using the ARM Template Viewer for VS Code:

39790-export.png

Notice that the deployment of the AppServicePlan follows another lifecycle as it is shared across multple appservices. Therefore it is not part of the deployment to this particular resource group. It does happen within the same pipeline, but in an earlier job. And in most cases, we are adding an additional AppService to an existing AppServicePlan, which might have been deployed days or even weeks back in time.


0 Votes 0 ·
export.png (336.8 KiB)

@cvationshm, Thanks for the follow-up and sharing the requested details. Yes, I was referring to the SitePackages for the package folder. For a closer look, I' have reached out to you offline.

1 Vote 1 ·

0 Answers