microsoft / azure-pipelines-tasks

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

[BUG]: AzureFunctionApp@2 does not "Remove additional files at destination" #18922

Open jryutzy opened 10 months ago

jryutzy commented 10 months ago

Task name

AzureFunctionAppV2

Task version

2

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

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

NA

Operation system

Windows 11

Task log

I am using the AzureRmWebAppDeployment@4 task to deploy Web and API App Services
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-rm-web-app-deployment-v4?view=azure-pipelines#web-deploy

I use a windows agent so I can use WebDeploy and removeAdditionalFilesFlag: true so that all existing files on app service are deleted before publshing.

The documentation for AzureRmWebAppDeployment@4
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/azure-function-app-v2?view=azure-pipelines
says to use AzureFunctionApp@2 for an Azure Function deploy.

I have my Azure Function deploying but not matter what I try I can't get the Remove additional files at destination functionality like I do when I publish the Azure Function from Visual Studio or like the AzureRmWebAppDeployment@4 task gives for a Web/API publish with the removeAdditionalFilesFlag set to true.

Does the AzureFunctionApp@2 support a way to clean the Azure Function App's files in wwwroot before publishing?

If not, is there any other way to accomplish this?

Could I use the AzureRmWebAppDeployment@4 task to publish the Azure Function app even though you suggest not doing so?

Here is my task
      - task: AzureFunctionApp@2
        condition: eq(variables._deployAzureFunction, true)
        inputs:
          appType: functionApp
          azureSubscription: 'Service Principal (Manual)' # Service Connection Name          
          resourceGroupName: 'NAME OF RESOURCE GRUOP'
          appName: '$(_appServiceNameToDeploy)'
          deployToSlotOrASE: false # if deploy to an app service slot this should be true
          slotName: 'dev' # slot name if deploying to a slot
          package: '$(Pipeline.Workspace)/drop'
          deploymentMethod: 'zipDeploy' # DOES NOT SEEM TO WORK: delete app service files before publishing
          removeAdditionalFilesFlag: true # DOES NOT SEEM TO WORK: delete app service files before publishing
          appSettings: '-RequestTimeout 4000'
        name: DeployToDev_AzureFunction  # because we're going to depend on it, we need to name the step
      - script: echo DeployToDev.AppServiceApplicationUrl=$(DeployToDev_AzureFunction.AppServiceApplicationUrl) # this step uses the output variable

Relevant log output

Starting: DeployToDev_AzureFunction
==============================================================================
Task         : Azure Functions Deploy
Description  : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications
Version      : 2.227.0
Author       : Microsoft Corporation
Help         : https://aka.ms/azurefunctiontroubleshooting
==============================================================================
Got service connection details for Azure App Service:'becht-lab-jyutzy-automatedbuild-net6-azurefunction-dev'
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.
Deploy logs can be viewed at https://****-azurefunction-dev.scm.azurewebsites.net/zzzzzzzzz
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.
Updating App Service Application settings. Data: {"RequestTimeout":"4000"}
App Service Application settings are already present.
Finishing: DeployToDev_AzureFunction

Aditional info

No response

FinVamp1 commented 10 months ago

Hello, the Run From Package and Zip Deploy Functionality should mean that any additional files present in home/site/wwwroot would be removed. I'll review this work item and come back to you.

jryutzy commented 10 months ago

I had a file named zzzappsettings.json and it was not removed. Existing files were overwritten but it didn’t clear the directory like I believe it should have. The AzureRmWebAppDeployment taskImentioned works correctly when you pass removeAdditionalFilesFlag: true

I searched for a App Service task that would allow me to just run a script (powershell, etc) against the AppService/AzurFunction but did not see one. If I could run a script against the AppService/AzureFunction wwwroot folder I could purge the files manually before I use the deploy task.

FinVamp1 commented 5 months ago

@jryutzy if you could share your YAML for the Function App Task and then I can see if there is an improvement that we can make to help with this. As I mentioned above the Zip deployment is our recommended way of deploying and so this should either mount or copy the zip to home/site/wwwroot. If the deployment type is set to zipDeploy rather than auto or Run From Package then it may keep existing files. Our recommendation would be to use Run From Package to make sure additional files are removed.

FinVamp1 commented 4 months ago

@jryutzy did you have an updates to share on this?