AzureFunctionApp@2 - Azure Functions Deploy v2 task

Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications.

Syntax

# Azure Functions Deploy v2
# Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications.
- task: AzureFunctionApp@2
  inputs:
    connectedServiceNameARM: # string. Alias: azureSubscription. Required. Azure Resource Manager connection. 
    appType: # 'functionApp' | 'functionAppLinux'. Required. App type. 
    #isFlexConsumption: false # boolean. Is Function App on Flex Consumption Plan. Default: false.
    appName: # string. Required. Azure Functions App name. 
    #deployToSlotOrASE: false # boolean. Optional. Use when appType != "" && isFlexConsumption = false. Deploy to Slot or App Service Environment. Default: false.
    #resourceGroupName: # string. Required when deployToSlotOrASE = true. Resource group. 
    #slotName: 'production' # string. Required when deployToSlotOrASE = true. Slot. Default: production.
    package: '$(System.DefaultWorkingDirectory)/**/*.zip' # string. Required. Package or folder. Default: $(System.DefaultWorkingDirectory)/**/*.zip.
    #runtimeStack: # 'DOTNET|6.0' | 'DOTNET-ISOLATED|6.0' | 'DOTNET-ISOLATED|7.0' | 'DOTNET-ISOLATED|8.0' | 'JAVA|8' | 'JAVA|11' | 'JAVA|17' | 'JAVA|21' | 'NODE|14' | 'NODE|16' | 'NODE|18' | 'NODE|20' | 'PYTHON|3.8' | 'PYTHON|3.9' | 'PYTHON|3.10' | 'PYTHON|3.11'. Optional. Use when appType = functionAppLinux && isFlexConsumption = false. Runtime stack. 
  # Application and Configuration Settings
    #appSettings: # string. App settings. 
  # Additional Deployment Options
    #deploymentMethod: 'auto' # 'auto' | 'zipDeploy' | 'runFromPackage'. Required when appType != "" && isFlexConsumption = false && appType != "" && package NotEndsWith .war && Package NotEndsWith .jar. Deployment method. Default: auto.
# Azure Functions Deploy v2
# Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications.
- task: AzureFunctionApp@2
  inputs:
    connectedServiceNameARM: # string. Alias: azureSubscription. Required. Azure Resource Manager connection. 
    appType: # 'functionApp' | 'functionAppLinux'. Required. App type. 
    appName: # string. Required. Azure Functions App name. 
    #deployToSlotOrASE: false # boolean. Optional. Use when appType != "". Deploy to Slot or App Service Environment. Default: false.
    #resourceGroupName: # string. Required when deployToSlotOrASE = true. Resource group. 
    #slotName: 'production' # string. Required when deployToSlotOrASE = true. Slot. Default: production.
    package: '$(System.DefaultWorkingDirectory)/**/*.zip' # string. Required. Package or folder. Default: $(System.DefaultWorkingDirectory)/**/*.zip.
    #runtimeStack: # 'DOTNET|2.2' | 'DOTNET|3.1' | 'DOTNET|6.0' | 'DOTNET-ISOLATED|7.0' | 'JAVA|8' | 'JAVA|11' | 'NODE|8' | 'NODE|10' | 'NODE|12' | 'NODE|14' | 'NODE|16' | 'NODE|18' | 'PYTHON|3.6' | 'PYTHON|3.7' | 'PYTHON|3.8' | 'PYTHON|3.9' | 'PYTHON|3.10'. Optional. Use when appType = functionAppLinux. Runtime stack. 
  # Application and Configuration Settings
    #appSettings: # string. App settings. 
  # Additional Deployment Options
    #deploymentMethod: 'auto' # 'auto' | 'zipDeploy' | 'runFromPackage'. Required when appType != "" && package NotEndsWith .war && Package NotEndsWith .jar. Deployment method. Default: auto.

Inputs

connectedServiceNameARM - Azure Resource Manager connection
Input alias: azureSubscription. string. Required.

Select the Azure Resource Manager subscription for the deployment.


appType - App type
string. Required. Allowed values: functionApp (Function App on Windows), functionAppLinux (Function App on Linux).

Select the Azure Function App type for the deployment.


isFlexConsumption - Is Function App on Flex Consumption Plan
boolean. Default value: false.

Set to true if function app is on a Flex Consumption plan.


appName - Azure Functions App name
string. Required.

Specify the name of an existing Azure Functions App. The Function Apps listed will be based on the selected app type.


deployToSlotOrASE - Deploy to Slot or App Service Environment
boolean. Optional. Use when appType != "" && isFlexConsumption = false. Default value: false.

Deploys to an existing deployment slot or Azure App Service Environment. For both targets, the task needs a Resource group name.

If the deployment target is a slot, it will default to the production slot. Any other existing slot name can also be provided.

If the deployment target is an Azure App Service Environment, leave the slot name as production and specify the Resource group name.


deployToSlotOrASE - Deploy to Slot or App Service Environment
boolean. Optional. Use when appType != "". Default value: false.

Deploys to an existing deployment slot or Azure App Service Environment. For both targets, the task needs a Resource group name.

If the deployment target is a slot, it will default to the production slot. Any other existing slot name can also be provided.

If the deployment target is an Azure App Service Environment, leave the slot name as production and specify the Resource group name.


resourceGroupName - Resource group
string. Required when deployToSlotOrASE = true.

The Resource group name is required when the deployment target is either a deployment slot or an App Service Environment.

Enters or selects the Azure Resource group that contains the Azure App Service specified above.


slotName - Slot
string. Required when deployToSlotOrASE = true. Default value: production.

Enters or selects an existing slot, excluding the Production slot.


slotName - Slot
string. Required when deployToSlotOrASE = true. Default value: production.

Enter or Select an existing Slot other than the Production slot.


package - Package or folder
string. Required. Default value: $(System.DefaultWorkingDirectory)/**/*.zip.

The file path to the package or folder that contains App Service content generated by MSBuild or a compressed zip file. Variables ( Build | Release) and wildcards are supported. For example, $(System.DefaultWorkingDirectory)/**/*.zip.


runtimeStack - Runtime stack
string. Optional. Use when appType = functionAppLinux && isFlexConsumption = false. Allowed values: DOTNET|6.0, DOTNET-ISOLATED|6.0, DOTNET-ISOLATED|7.0, DOTNET-ISOLATED|8.0, JAVA|8, JAVA|11, JAVA|17, JAVA|21, NODE|14, NODE|16, NODE|18, NODE|20, PYTHON|3.8, PYTHON|3.9, PYTHON|3.10, PYTHON|3.11.

Specify the framework and version your function app will run on. You can use any of the supported runtime versions. Old values like DOCKER|microsoft/azure-functions-* are deprecated. New values are listed in the drop-down list in the task assistant. If there is a newer version of a framework available in the supported runtime versions you can specify it even if it is not in the list.

Note

This value currently doesn't update the linuxFxVersion that the site is running on. This means you can't update the stack from Node 18 to Node 20. The task currently only updates the app settings.


runtimeStack - Runtime stack
string. Optional. Use when appType = functionAppLinux. Allowed values: DOTNET|2.2 (DOTNET|2.2 (functionapp v2)), DOTNET|3.1 (DOTNET|3.1 (functionapp v3)), DOTNET|6.0 (DOTNET|6.0 (functionapp v4)), DOTNET-ISOLATED|7.0 (DOTNET-ISOLATED|7.0 (functionapp v4)), JAVA|8 (JAVA|8 (functionapp v2/v3/v4)), JAVA|11 (JAVA|11 (functionapp v3/v4)), NODE|8 (NODE|8 (functionapp v2)), NODE|10 (NODE|10 (functionapp v2/v3)), NODE|12 (NODE|12 (functionapp v3)), NODE|14 (NODE|14 (functionapp v3/v4)), NODE|16 (NODE|16 (functionapp v4)), NODE|18 (NODE|18 (functionapp v4)), PYTHON|3.6 (PYTHON|3.6 (functionapp v2/v3)), PYTHON|3.7 (PYTHON|3.7 (functionapp v2/v3/v4)), PYTHON|3.8 (PYTHON|3.8 (functionapp v3/v4)), PYTHON|3.9 (PYTHON|3.9 (functionapp v3/v4)), PYTHON|3.10 (PYTHON|3.10 (functionapp v3/v4)).

Specify the framework and version your function app will run on. You can use any of the supported runtime versions. Old values like DOCKER|microsoft/azure-functions-* are deprecated. New values are listed in the drop-down list in the task assistant. If there is a newer version of a framework available in the supported runtime versions you can specify it even if it is not in the list.


appSettings - App settings
string.

Enter the application settings using the syntax -key value (for example: -Port 5000 -RequestTimeout 5000 -WEBSITE_TIME_ZONE). Enclose values that contain spaces in double quotes (for example: "Eastern Standard Time").


deploymentMethod - Deployment method
string. Required when appType != "" && isFlexConsumption = false && appType != "" && package NotEndsWith .war && Package NotEndsWith .jar. Allowed values: auto (Auto-detect), zipDeploy (Zip Deploy), runFromPackage (Zip Deploy with Run From Package). Default value: auto.

Specifies the deployment method for the app. Linux Consumption apps do not support this configuration.


deploymentMethod - Deployment method
string. Required when appType != "" && package NotEndsWith .war && Package NotEndsWith .jar. Allowed values: auto (Auto-detect), zipDeploy (Zip Deploy), runFromPackage (Zip Deploy with Run From Package). Default value: auto.

Specifies the deployment method for the app. Linux Consumption apps do not support this configuration.


deploymentMethod - Deployment method
string. Required when appType != "" && package NotEndsWith .war && Package NotEndsWith .jar. Allowed values: auto (Auto-detect), zipDeploy (Zip Deploy), runFromPackage (Zip Deploy with Run From Package). Default value: auto.

Chooses the deployment method for the app. Linux Consumption apps do not support this configuration.s


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

This task defines the following output variables, which you can consume in downstream steps, jobs, and stages.

AppServiceApplicationUrl
Application URL of the selected Azure Function App.

Remarks

The Azure Function Deployment task is used to update Azure Functions to deploy Functions to Azure. The task works on cross platform Azure Pipelines agents running Windows, Linux or Mac and uses the underlying deployment technologies of RunFromPackage, Zip Deploy and Kudu REST APIs.

The task works for the Azure Functions supported languages.

Pre-requisites for the task

The following pre-requisites need to be setup in the target machine(s) for the task to work properly.

Azure Function

The task is used to deploy an Azure Functions project to an existing Azure Function. The Azure Function app should exist prior to running the task. The Azure Function App can be created from the Azure portal. Alternatively, the Azure PowerShell task can be used to run AzureRM PowerShell scripts to provision and configure the Azure Function app.

The task can be used to deploy Azure Functions (Windows/Linux).

Azure Subscription

To deploy to Azure, an Azure subscription has to be linked to Azure Pipelines using the Services tab in the Account Administration section. Add the Azure subscription to use in the Build or Release Management definition by opening the Account Administration screen (gear icon on the top-right of the screen) and then click on the Services Tab.

Create the ARM service endpoint and use Azure Resource Manager endpoint type. For more details, follow the steps listed in the link here.

The task does not work with the Azure Classic service endpoint and it will not list these connections in the parameters in the task.

Deployment methods

Several deployment methods are available in this task.

To change the package-based deployment option in a designer task, expand Additional Deployment Options and enable Select Deployment Method.

Based on the type of Azure App Service and Azure Pipelines agent, the task uses a suitable deployment technology. The deployment technologies used by tasks are as follows:

By default, the task attempts to select the appropriate deployment technology based on the input package, App Service type, and agent OS.

  • If a post-deployment script is provided, use Zip Deploy.
  • If the App Service type is Web App on Linux, use Zip Deploy.
  • If a .war file is provided, use War Deploy.
  • If a .jar file is provided, use Run-From-Zip.
  • For all other tasks, use Run From Package (via Zip Deploy).

On a non-Windows agent (for any App Service type), the task relies on the Kudu REST API to deploy the web app.

Kudu REST API

The Kudu REST API works on both Windows and Linux automation agents when the target is a Web App on Windows, a Web App on Linux (built-in source), or a function app. The task uses Kudu to copy files to the Azure App Service.

Zip Deploy

Zip Deploy creates a .zip deployment package from the chosen package or folder. It then deploys the file contents to the wwwroot folder of the App Service name function app in Azure. This option overwrites all existing content in the wwwroot folder. For more information, see Zip deployment for Azure Functions.

Run From Package

Run From Package creates the same deployment package as Zip Deploy. Instead of deploying files to the wwwroot folder, the Functions runtime mounts the entire package. When you use this option, files in the wwwroot folder become read-only. For more information, see Run your Azure Functions from a package file.

Troubleshooting

Error: Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.

The task uses the service principal in the service connection to authenticate with Azure. If the service principal has expired or doesn't have permissions to the App Service, the task fails with this error. Verify the validity of the service principal used and that it's present in the app registration. For more information, see Use role-based access control to manage access to your Azure subscription resources. This blog post also contains more information about using service principal authentication.

SSL error

If you want to use a certificate in App Service, the certificate must be signed by a trusted certificate authority. If your web app gives you certificate validation errors, you're probably using a self-signed certificate. Set a variable named VSTS_ARM_REST_IGNORE_SSL_ERRORS to the value true in the build or release pipeline to resolve the error.

A release hangs for long time and then fails

This problem could be the result of insufficient capacity in your App Service plan. To resolve this problem, you can scale up the App Service instance to increase available CPU, RAM, and disk space or try with a different App Service plan.

5xx error codes

If you're seeing a 5xx error, check the status of your Azure service.

Azure Function suddenly stopped working

Azure Functions may suddenly stop working if more than one year has passed since the last deployment. If you deploy with "RunFromPackage" in "deploymentMethod", a SAS with an expiration date of 1 year is generated and set as the value of "WEBSITE_RUN_FROM_PACKAGE" in the application configuration. Azure Functions uses this SAS to reference the package file for function execution, so if the SAS has expired, the function will not be executed. To resolve this issue, deploy again to generate a SAS with an expiration date of one year.

Error: No package found with specified pattern

Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.

Error: Publish using zip deploy option is not supported for msBuild package type

Web packages created via the MSBuild task (with default arguments) have a nested folder structure that can be deployed correctly only by Web Deploy. The publish-to-zip deployment option can't be used to deploy those packages. To convert the packaging structure, take these steps:

  1. In the Build solution task, change the MSBuild Arguments to /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl="$(System.DefaultWorkingDirectory)\\WebAppContent":

    Screenshot that shows the Build solution values.

  2. Add an Archive task and change the values as follows:

    1. Change Root folder or file to archive to $(System.DefaultWorkingDirectory)\\WebAppContent.

    2. Clear the Prepend root folder name to archive paths check box:

      Screenshot that shows the Archive values.

Function app deployment on Windows succeeds but the app doesn't work

This problem could occur if a web.config file isn't present in your app. You can either add a web.config file to your source or automatically generate one by using the Application and Configuration Settings of the task.

  1. Select the task and go to Generate web.config parameters for Python, Node.js, Go and Java apps:

    Screenshot that shows the Generate web.config parameters section.

  2. Select the More button (...) under Generate web.config parameters for Python, Node.js, Go and Java apps to edit the parameters:

    Screenshot that shows the Generate web.config parameters.

  3. Select your application type in the Application framework list.

  4. Select OK. Doing so will populate the web.config parameters required to generate the web.config file.

FAQs

How should I configure my service connection?

This task requires an Azure Resource Manager service connection.

How should I configure web job deployment with Application Insights?

When you're deploying to an App Service, if you have Application Insights configured and you've enabled Remove additional files at destination, you also need to enable Exclude files from the App_Data folder. Enabling this option keeps the Application Insights extension in a safe state. This step is required because the Application Insights continuous WebJob is installed into the App_Data folder.

How should I configure my agent if it's behind a proxy while I'm deploying to App Service?

If your self-hosted agent requires a web proxy, you can inform the agent about the proxy during configuration. Doing so allows your agent to connect to Azure Pipelines or Azure DevOps Server through the proxy. Learn more about running a self-hosted agent behind a web proxy.

I can't deploy to an internal App Service Environment by using an Azure Resource Manager service connection and a Microsoft-hosted agent

By design, a Microsoft-hosted agent won't work with an App Service Environment. Instead, you need to configure a private agent on a virtual machine that's in the same virtual network as the App Service Environment. Also, set a private DNS zone to enable communication between the resources.

Examples

Here's a sample YAML snippet that deploys Azure functions on Windows:


variables:
  azureSubscription: Contoso
  # To ignore SSL error, uncomment the below variable
  # VSTS_ARM_REST_IGNORE_SSL_ERRORS: true

steps:
- task: AzureFunctionApp@2
  displayName: Azure Function App Deploy
  inputs:
    azureSubscription: $(azureSubscription)
    appName: samplefunctionapp
    appType: functionApp
    package: $(System.DefaultWorkingDirectory)/**/*.zip

To deploy a function on Linux, add the appType parameter and set it to appType: functionAppLinux. If you don't specify a value, functionApp is the default.

To explicitly specify the deployment method as Zip Deploy, add the parameter deploymentMethod: zipDeploy. Another supported value for this parameter is runFromPackage. If you don't specify a value, auto is the default.

For a walkthrough that shows how to create a CI/CD pipeline, see Build and deploy Java to Azure Functions.

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands None
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 2.104.1 or greater
Task category Deploy