microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.42k stars 2.58k forks source link

[BUG]: AzureFunctionApp@2 recommending to add a variable that it removes #18970

Open israelhdz08 opened 9 months ago

israelhdz08 commented 9 months ago

Task name

AzureFunctionApp

Task version

2

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

Azure DevOps Server (Please specify exact version in the textbox below)

Azure DevOps Server Version (if applicable)

No response

Operation system

Windows 11

Task log

Got service connection details for Azure App Service:'<FunctionName>'
NOTE: Skipping AzureWebJobsStorage connection string validation since Key Vault reference is used.
Deleting App Service Application settings. Data: ["WEBSITE_RUN_FROM_ZIP","WEBSITE_RUN_FROM_PACKAGE"]
App Service Application settings are already present.
Validating deployment package for functions app before Zip Deploy
##[warning]"ZipDeploy Validation WARNING: It is recommended to set app setting WEBSITE_RUN_FROM_PACKAGE = 1 unless you are targeting one of the following scenarios: 1. Using portal editing. 2. Running post deployment scripts. 3. Need write permission in wwwroot. 4. Using custom handler with special requirements. NOTE: If you decide to update app setting WEBSITE_RUN_FROM_PACKAGE = 1, you will have to re-deploy your code. "
Package deployment using ZIP Deploy initiated.
....

The task first deletes the WEBSITE_RUN_FROM_PACKAGE variable from the Azure function, then it complains that it should exist.

FinVamp1 commented 9 months ago

Hi there, thanks for reporting this. Can you share your YAML file?

israelhdz08 commented 9 months ago
  task: AzureFunctionApp@2
  displayName: 'Deploy function'
  inputs:
    connectedServiceNameARM: 'ServiceConnector' 
    appType: 'functionApp' 
    appName: 'functionName' 
    deployToSlotOrASE: true
    resourceGroupName: 'resourceGroup' 
    slotName: 'rc'
    package: '$(System.DefaultWorkingDirectory)/function.zip'
    deploymentMethod: 'zipDeploy'
FinVamp1 commented 9 months ago

Hello, @israelhdz08 in order for this to be a consistent experience we need to carry out the following steps.

1) Check the App Settings and remove any old app Settings that may conflict with the planned deployment options. 2) Validate the App Configuration to ensure that the app is ready for Deployment and log the warning messages. For this we call an endpoint on the Kudu\SCM Site "/api/zipdeploy/validate" 3) Before deploying the Zip Deploy package we will set back WEBSITE_RUN_FROM_PACKAGE=1 or URL depending on the scenario.

As the user owns the App Settings we need to follow this order to ensure that the app settings are configured correctly and to support moving from Run From Package =1 from Run From Package =URL.

I can see how this might be confusing and if you have any suggestions about how you would like to see this presented. We may have to think about if this could affect other scenarios.

Adding @patelchandni as well.

HaochenQ commented 4 months ago

Hi,

I also face the same issue.

Occasionally, I have the below warning with this Function task. image

[warning]"ZipDeploy Validation WARNING: It is recommended to set app setting WEBSITE_RUN_FROM_PACKAGE = 1 unless you are targeting one of the following scenarios: 1. Using portal editing. 2. Running post deployment scripts. 3. Need write permission in wwwroot. 4. Using custom handler with special requirements. NOTE: If you decide to update app setting WEBSITE_RUN_FROM_PACKAGE = 1, you will have to re-deploy your code. "

I am using AUTO-DETECT as the deployment method.

- task: AzureFunctionApp@2
    condition: eq('${{ parameters.action }}', 'create')
    inputs:
      connectedServiceNameARM: '${{parameters.connectionName}}'
      appType: 'functionApp'
      appName: '$(FunctionAppName)'
      package: '$(Pipeline.Workspace)/**/*.zip'
      appSettings:
        '
        '
      deploymentMethod: 'auto'

When I see this error, although the deployment is successful the content of my function is not updated so I have a re-run the pipeline and it usually fixes the issue automatically.

Cheers,

FinVamp1 commented 4 months ago

This is in our backlog. Will check to see what improvements we could make to help this.

RobinDijkstra commented 3 months ago

Same here, this seems more like a bug. We're using deployment method 'runFromPackage'. Whenever we see this warning, there's nothing deployed although the task reports that the web package has been deployed. When re-running the pipeline stage, the warning does not appear and the deploy goes fine.

   - task: AzureFunctionApp@2
      displayName: 'Deploy FunctionApp'
      inputs: 
        azureSubscription: '${{ parameters.azureSubscription }}'
        appType: 'functionApp'
        appName: '${{ parameters.resourceName }}'
        deployToSlotOrASE: true
        resourceGroupName: '${{ parameters.resourceGroupName }}'
        slotName: 'deployment'
        package: '${{ parameters.packagePath }}'
        deploymentMethod: 'runFromPackage'

Task log:

Starting: Deploy FunctionApp

Task : Azure Functions Deploy Description : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications Version : 2.231.0 Author : Microsoft Corporation Help : https://aka.ms/azurefunctiontroubleshooting

Got service connection details for Azure App Service:'xyz' Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"} Deleting App Service Application settings. Data: ["WEBSITE_RUN_FROM_ZIP"] Updated App Service Application settings and Kudu Application settings. Validating deployment package for functions app before Zip Deploy

[warning]"ZipDeploy Validation WARNING: It is recommended to set app setting WEBSITE_RUN_FROM_PACKAGE = 1 unless you are targeting one of the following scenarios: 1. Using portal editing. 2. Running post deployment scripts. 3. Need write permission in wwwroot. 4. Using custom handler with special requirements. NOTE: If you decide to update app setting WEBSITE_RUN_FROM_PACKAGE = 1, you will have to re-deploy your code. "

Package deployment using ZIP Deploy initiated. Deploy logs can be viewed at https://xyz-deployment.scm.azurewebsites.net/api/deployments/abc/log The web package has been deployed to App Service. Please note that the package mount or extraction errors will be logged in the deployment logs in the location above. NOTE: Run From Package makes wwwroot read-only, so you will receive an error when writing files to this directory. App Service Application URL: https://xyz-deployment.azurewebsites.net/ Finishing: Deploy FunctionApp

Cuflee commented 3 months ago

We all of the sudden have the exact same issue @RobinDijkstra is mentioning above. Is there any update about his? We now don't dare to deploy anything to production in fear that we would have the same issue there as well.

We already rolled back any of our latest changes, but the issue seems Azure related. The functions all apear running, but they don't process any messages anymore after deploy.

Sometimes after rerunning the pipeline it works for several minutes and then breaks down again without any exception being logged (and the status still "running").

FinVamp1 commented 3 months ago

If you're still seeing this issue can you provide a Site Region and perhaps also check the AppSettings and let me know if you have this app setting? WEBSITE_ENABLE_SYNC_UPDATE_SITE = true or 1

Mivaweb commented 3 months ago

Since a couple of weeks, we are facing the same issue using the AzureFunctionApp@1 task. Redeploy fixes the issue. We are in the West Europe region and we have the following app settings active:

image

Yaml:

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy'
  inputs:
    azureSubscription: ${{ parameters.azServiceConnection }}
    appType: functionApp
    appName: 'func-${{ parameters.env }}-01'
    package: '$(Agent.BuildDirectory)\drop\Function.zip'

Task output with warning:

Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"}
Deleting App Service Application settings. Data: ["WEBSITE_RUN_FROM_ZIP"]
Updated App Service Application settings and Kudu Application settings.
Validating deployment package for functions app before Zip Deploy
##[warning]"ZipDeploy Validation WARNING: It is recommended to set app setting WEBSITE_RUN_FROM_PACKAGE = 1 u***ess
Cuflee commented 3 months ago

We still have the issue but found a work-around by setting the pipeline into debug mode. We did this in order to troubleshoot the issue, but found that when the pipeline is running in debug mode the issue does not occur. Perhaps because of a process taking slightly longer in debug mode so something can complete. But it is strange that this all of the sudden started happening. All of the alterations mentioned within this thread were already tried and did not resolve the issue.

RobinDijkstra commented 3 months ago

We're also having the setting WEBSITE_ENABLE_SYNC_UPDATE_SITE = true on all out function apps and are also located in the West Europe region.

ki-dro commented 1 month ago

We are also experiencing this issue. Are there any updates?

FinVamp1 commented 1 month ago

Hello all,

We've been investigating this issue and there is a timing issue where this can happen.

  1. AzureFunctionApp task sets WEBSITE_RUN_FROM_PACKAGE
  2. It calls the Validation Endpoint that exists on the Kudu\SCM website and this checks the app setting which isn't set yet.
  3. Validation fails but deployment succeeds albeit without using Run From Package.

Our investigations have identified that the AzureRMWebAppDeployment tasks have logic to detect this situation and will wait until Kudu\SCM has the right settings.

So if you're running into this issue please let us know if using the AzureRMWebAppDeployment task resolves the issue for you and we are planning to make this change into the Functions Task in the current sprint.

komjera commented 1 month ago

We are also affected by this and when I tried to reproduce the issue with system.debug set to true I wasn't able to, which might indicate that this is indeed a timing issue that is "resolved" by slowing down the pipeline with debug mode.

FinVamp1 commented 1 month ago

We have a tracking item for the fix for this here Update FunctionApp Task

RobinDijkstra commented 1 month ago

@FinVamp1 Thanks, I've found it but there is a character too many in the link.

FinVamp1 commented 1 month ago

@FinVamp1 Thanks, I've found it but there is a character too many in the link.

Thanks for the spot, I've updated the link.