Events
17 Mar, 23 - 21 Mar, 23
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Azure DevOps Services | Azure DevOps Server 2020 | Azure DevOps Server 2019
Note
Starting June 1, 2024, newly created App Service apps can generate a unique default hostname that uses the naming convention <app-name>-<random-hash>.<region>.azurewebsites.net
. Existing app names remain unchanged. For example:
myapp-ds27dh7271aah175.westus-01.azurewebsites.net
For more information, see Unique Default Hostname for App Service Resource.
Use Azure Pipelines to automatically deploy your web app to Azure App Service on every successful build. Azure Pipelines lets you build, test, and deploy with continuous integration (CI) and continuous delivery (CD) using Azure DevOps.
YAML pipelines are defined using a YAML file in your repository. A step is the smallest building block of a pipeline and can be a script or task (prepackaged script). Learn about the key concepts and components that make up a pipeline.
You'll use the Azure Web App task (AzureWebApp
) to deploy to Azure App Service in your pipeline. For more complicated scenarios such as needing to use XML parameters in your deploy, you can use the Azure App Service deploy task (AzureRmWebAppDeployment).
The code examples in this section assume you're deploying an ASP.NET web app. You can adapt the instructions for other frameworks.
Learn more about Azure Pipelines ecosystem support.
Sign in to your Azure DevOps organization and navigate to your project.
Go to Pipelines, and then select New Pipeline.
When prompted, select the location of your source code: either Azure Repos Git or GitHub.
You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.
When the list of repositories appears, select your repository.
You might be redirected to GitHub to install the Azure Pipelines app. If so, select Approve & install.
When the Configure tab appears, select ASP.NET Core.
When your new pipeline appears, take a look at the YAML to see what it does. When you're ready, select Save and run.
Click the end of the YAML file, then select Show assistant.'
Use the Task assistant to add the Azure Web App task.
Alternatively, you can add the Azure App Service deploy (AzureRmWebAppDeployment) task.
Choose your Azure subscription. Make sure to Authorize your connection. The authorization creates the required service connection.
Select the App type, App name, and Runtime stack based on your App Service app. Your complete YAML should look similar to the following code.
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
- task: AzureWebApp@1
inputs:
azureSubscription: '<service-connection-name>'
appType: 'webAppLinux'
appName: '<app-name>'
package: '$(System.DefaultWorkingDirectory)/**/*.zip'
To deploy a .zip web package (for example, from an ASP.NET web app) to an Azure Web App, use the following snippet to deploy the build to an app.
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
- task: AzureWebApp@1
inputs:
azureSubscription: '<service-connection-name>'
appType: 'webAppLinux'
appName: '<app-name>'
package: '$(System.DefaultWorkingDirectory)/**/*.zip'
By default, your deployment happens to the root application in the Azure Web App. You can deploy to a specific virtual application by using the VirtualApplication
property of the Azure App Service deploy (AzureRmWebAppDeployment
) task:
- task: AzureRmWebAppDeployment@4
inputs:
VirtualApplication: '<name of virtual application>'
The following example shows how to deploy to a staging slot, and then swap to a production slot:
- task: AzureWebApp@1
inputs:
azureSubscription: '<service-connection-name>'
appType: webAppLinux
appName: '<app-name>'
deployToSlotOrASE: true
resourceGroupName: '<name of resource group>'
slotName: staging
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
- task: AzureAppServiceManage@0
inputs:
azureSubscription: '<service-connection-name>'
appType: webAppLinux
WebAppName: '<app-name>'
ResourceGroupName: '<name of resource group>'
SourceSlot: staging
SwapWithProduction: true
webAppLinux
to deploy to a Web App on Linux.deployToSlotOrASE
is true.production
. Required if deployToSlotOrASE
is true.SwapWithProduction
is true.You can use jobs in your YAML file to set up a pipeline of deployments. By using jobs, you can control the order of deployment to multiple web apps.
jobs:
- job: buildandtest
pool:
vmImage: ubuntu-latest
steps:
# publish an artifact called drop
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
# deploy to Azure Web App staging
- task: AzureWebApp@1
inputs:
azureSubscription: '<service-connection-name>'
appType: <app type>
appName: '<staging-app-name>'
deployToSlotOrASE: true
resourceGroupName: <group-name>
slotName: 'staging'
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'
- job: deploy
dependsOn: buildandtest
condition: succeeded()
pool:
vmImage: ubuntu-latest
steps:
# download the artifact drop from the previous job
- task: DownloadPipelineArtifact@2
inputs:
source: 'current'
artifact: 'drop'
path: '$(Pipeline.Workspace)'
- task: AzureWebApp@1
inputs:
azureSubscription: '<service-connection-name>'
appType: <app type>
appName: '<production-app-name>'
resourceGroupName: <group-name>
package: '$(Pipeline.Workspace)/**/*.zip'
To do this in YAML, you can use one of the following techniques:
The following example shows how to use step conditions to deploy only builds that originate from the main branch:
- task: AzureWebApp@1
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
inputs:
azureSubscription: '<service-connection-name>'
appName: '<app-name>'
To learn more about conditions, see Specify conditions.
The Azure App Service deploy (AzureRmWebAppDeployment
) task can deploy to App Service using Web Deploy.
trigger:
- main
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration $(buildConfiguration)'
zipAfterPublish: true
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '<service-connection-name>'
appType: 'webApp'
WebAppName: '<app-name>'
packageForLinux: '$(System.DefaultWorkingDirectory)/**/*.zip'
enableCustomDeployment: true
DeploymentType: 'webDeploy'
The Azure Web App task (AzureWebApp
) is the simplest way to deploy to an Azure Web App. By default, your deployment happens to the root application in the Azure Web App.
The Azure App Service Deploy task (AzureRmWebAppDeployment
) can handle more custom scenarios, such as:
Note
File transforms and variable substitution are also supported by the separate File Transform task for use in Azure Pipelines. You can use the File Transform task to apply file transformations and variable substitutions on any configuration and parameters files.
In YAML pipelines, depending on your pipeline, there may be a mismatch between where your built web package is saved and where the deploy task is looking for it. For example, the AzureWebApp
task picks up the web package for deployment. For example, the AzureWebApp task looks in $(System.DefaultWorkingDirectory)/**/*.zip
. If the web package is deposited elsewhere, modify the value of package
.
This error occurs in the AzureRmWebAppDeployment task when you configure the task to deploy using Web Deploy, but your agent isn't running Windows. Verify that your YAML has something similar to the following code:
pool:
vmImage: windows-latest
For troubleshooting information on getting Microsoft Entra ID authentication to work with the AzureRmWebAppDeployment
task, see I can't Web Deploy to my Azure App Service using Microsoft Entra ID authentication from my Windows agent
Events
17 Mar, 23 - 21 Mar, 23
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Learning path
Deploy applications with Azure DevOps learning path - Training
Learn how to configure release pipelines that continuously build, test, and deploy your applications.
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Documentation
AzureWebApp@1 - Azure Web App v1 task
Deploy an Azure Web App for Linux or Windows.
AzureRmWebAppDeployment@4 - Azure App Service deploy v4 task
Deploy to Azure App Service a web, mobile, or API app using Docker, Java, .NET, .NET Core, Node.js, PHP, Python, or Ruby.
Deploy with Azure Pipelines - Azure App Service
Learn how to use Azure Pipelines to deploy your custom Windows container to App Service from a CI/CD pipeline.