Dela via


Deploy an Azure Web App

TFS 2017

Note

In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, runs are called builds, service connections are called service endpoints, stages are called environments, and jobs are called phases.

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 (pre-packaged script). Learn about the key concepts and components that make up a pipeline.

You'll use the Azure Web App task 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.

To learn how to deploy to an Azure Web App for Linux Containers, see Deploy an Azure Web App Container.

Note

This guidance applies to Team Foundation Server (TFS) version 2017.3 and later.

Prerequisites

Make sure you have the following items:

  • A GitHub account where you can create a repository. Create one for free.

  • An Azure DevOps organization. Create one for free. If your team already has one, then make sure you're an administrator of the Azure DevOps project that you want to use.

  • An ability to run pipelines on Microsoft-hosted agents. You can either purchase a parallel job or you can request a free tier.

Create an Azure App Service in the Azure portal

Create an Azure App Service on Linux or Windows with Azure Cloud Shell. To get started:

  1. Sign in to the Azure portal.
  2. Launch the Cloud Shell from the upper navigation pane of the portal. Open the Cloud Shell.

For more information, see Overview of Azure Cloud Shell.

Create an Azure App Service on Linux.

# Create a resource group
az group create --location eastus2 --name myapp-rg

# Create an app service plan of type Linux
az appservice plan create -g myapp-rg -n myapp-service-plan --is-linux

# Create an App Service from the plan 
az webapp create -g myapppipeline-rg -p myapp-service-plan -n my-app-dotnet --runtime "DOTNETCORE|3.1" 

Build your app with Azure Pipelines

YAML pipelines aren't available in TFS 2017.

Now you're ready to read through the rest of this topic to learn some of the more common changes that people make to customize an Azure Web App deployment.

Use the Azure Web App task

YAML pipelines aren't available in TFS 2017.

Use a service connection

To deploy to Azure App Service, you'll need to use an Azure Resource Manager service connection. The Azure service connection stores the credentials to connect from Azure Pipelines or Azure DevOps Server to Azure.

Learn more about Azure Resource Manager service connections. If your service connection is not working as expected, see Troubleshooting service connections.

YAML pipelines aren't available in TFS 2017.

Deploy to a virtual application

YAML pipelines aren't available in TFS 2017.

Deploy to a slot

YAML pipelines aren't available in TFS 2017.

Deploy to multiple web apps

YAML pipelines aren't available in TFS 2017.

Configuration changes

For most language stacks, app settings and connection strings can be set as environment variables at runtime. App settings can also be resolved from Key Vault using Key Vault references.

For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in <appSettings> in Web.config. You might want to apply a specific configuration for your web app target before deploying to it. This is useful when you deploy the same build to multiple web apps in a pipeline. For example, if your Web.config file contains a connection string named connectionString, you can change its value before deploying to each web app. You can do this either by applying a Web.config transformation or by substituting variables in your Web.config file.

Azure App Service Deploy task allows users to modify configuration settings in configuration files (*.config files) inside web packages and XML parameters files (parameters.xml), based on the stage name specified.

YAML pipelines aren't available in TFS 2017.

Deploying conditionally

You can choose to deploy only certain builds to your Azure Web App.

YAML pipelines aren't available in TFS 2017.

(Classic) Deploy with a release pipeline

You can use a release pipeline to pick up the artifacts published by your build and then deploy them to your Azure web site.

  1. Do one of the following to start creating a release pipeline:

    • If you've just completed a CI build, choose the link (for example, Build 20170815.1) to open the build summary. Then choose Release to start a new release pipeline that's automatically linked to the build pipeline.

    • Open the Releases tab in Azure Pipelines, open the + drop-down in the list of release pipelines, and choose Create release pipeline.

  2. The easiest way to create a release pipeline is to use a template. If you are deploying a Node.js app, select the Deploy Node.js App to Azure App Service template. Otherwise, select the Azure App Service Deployment template. Then choose Apply.

    Note

    The only difference between these templates is that Node.js template configures the task to generate a web.config file containing a parameter that starts the iisnode service.

  3. If you created your new release pipeline from a build summary, check that the build pipeline and artifact is shown in the Artifacts section on the Pipeline tab. If you created a new release pipeline from the Releases tab, choose the + Add link and select your build artifact.

  4. Choose the Continuous deployment icon in the Artifacts section, check that the continuous deployment trigger is enabled, and add a filter to include the main branch.

    Note

    Continuous deployment is not enabled by default when you create a new release pipeline from the Releases tab.

  5. Open the Tasks tab and, with Stage 1 selected, configure the task property variables as follows:

    • Azure Subscription: Select a connection from the list under Available Azure Service Connections or create a more restricted permissions connection to your Azure subscription. If you are using Azure Pipelines and if you see an Authorize button next to the input, click on it to authorize Azure Pipelines to connect to your Azure subscription. If you are using TFS or if you do not see the desired Azure subscription in the list of subscriptions, see Azure Resource Manager service connection to manually set up the connection.

    • App Service Name: Select the name of the web app from your subscription.

    Note

    Some settings for the tasks may have been automatically defined as stage variables when you created a release pipeline from a template. These settings cannot be modified in the task settings; instead you must select the parent stage item in order to edit these settings.

  6. Save the release pipeline.

Create a release to deploy your app

You're now ready to create a release, which means to run the release pipeline with the artifacts produced by a specific build. This will result in deploying the build:

  1. Choose + Release and select Create a release.

  2. In the Create a new release panel, check that the artifact version you want to use is selected and choose Create.

  3. Choose the release link in the information bar message. For example: "Release Release-1 has been created".

  4. In the pipeline view, choose the status link in the stages of the pipeline to see the logs and agent output.

  5. After the release is complete, navigate to your site running in Azure using the Web App URL http://{web_app_name}.azurewebsites.net, and verify its contents.

Deploy to an Azure Government cloud or to Azure Stack

Create a suitable service connection:

Deployment mechanisms

The preceding examples rely on the built-in Azure Web App task, which provides simplified integration with Azure.

If you use a Windows agent, this task uses Web Deploy technology to interact with the Azure Web App. Web Deploy provides several convenient deployment options, such as renaming locked files and excluding files from the App_Data folder during deployment.

If you use the Linux agent, the task relies on the Kudu REST APIs.

One thing worth checking before deploying is the Azure App Service access restrictions list. This list can include IP addresses or Azure Virtual Network subnets. When there are one or more entries, there is then an implicit "deny all" that exists at the end of the list. To modify the access restriction rules to your app, see Adding and editing access restriction rules in Azure portal. You can also modify/restrict access to your source control management (scm) site.

The Azure App Service Manage task is another task that's useful for deployment. You can use this task to start, stop, or restart the web app before or after deployment. You can also use this task to swap slots, install site extensions, or enable monitoring of the web app.

You can use the File Transform task to apply file transformations and variable substitutions on any configuration and parameters files.

If the built-in tasks don't meet your needs, you can use other methods to script your deployment. View the YAML snippets in each of the following tasks for some examples: