Azure web apps deployment

[ad_1]

Use the Azure App Service Deploy task (AzureRmWebAppDeployment) to deploy to an Azure web app.

Deploy a web deploy package (ASP.NET)

To deploy a .zip web deploy package (for example from an ASP.NET web app) to an Azure web app, add the following snippet to your .vsts-ci.yml file.

- task: AzureRmWebAppDeployment@3
  inputs:
    azureSubscription: '<Azure service endpoint>'
    WebAppName: '<Name of web app>'
    Package: $(build.artifactstagingdirectory)/**/*.zip

Deploy a Java app

If you are building a Java app, use the following snippet to deploy the web archive (.war).

- task: AzureRmWebAppDeployment@3
  inputs:
    azureSubscription: '<Azure service endpoint>'
    WebAppName: '<Name of web app>'
    Package: '$(System.DefaultWorkingDirectory)/**/*.war'

Deploy a JavaScript Node.js app

If you are building a JavaScript Node.js app, use the following snippet. It generates a web.config file during deployment and starts iisnode handler on the Azure web app.

- task: AzureRmWebAppDeployment@3
  inputs:
    azureSubscription: '<Azure service endpoint>'
    WebAppName: '<Name of web app>'
    Package: '$(System.DefaultWorkingDirectory)'
    GenerateWebConfig: true
    WebConfigParameters: '-Handler iisnode -NodeStartFile server.js -appType node'

What about the Azure service endpoint?

You must supply an Azure service endpoint to the AzureRmWebAppDeployment task. The Azure service endpoint stores the credentials to connect from VSTS to Azure. See Create an Azure service endpoint.

Deploying to a virtual application

By default, your deployment happens to the root application in the Azure web app. You can deploy to a specific virtual application using the following:

- task: AzureRmWebAppDeployment@3
  inputs:
    VirtualApplication: '<name of virtual application>'

Deploying to a slot

You can configure the Azure web app to have multiple slots. Slots allow you to safely deploy your app and test it, before making it available to your customers.

The following example shows how to deploy to a staging slot, and then swap to a production slot.

- task: AzureRmWebAppDeployment@3
  inputs:
    azureSubscription: '<Azure service endpoint>'
    WebAppName: '<name of web app>'
    DeployToSlotFlag: true
    ResourceGroupName: '<name of resource group>'
    SlotName: staging

- task: AzureAppServiceManage@0
  inputs:
    azureSubscription: '<Azure service endpoint>'
    WebAppName: '<name of web app>'
    ResourceGroupName: '<name of resource group>'
    SourceSlot: staging

Multiple web apps in a pipeline

You can use phases in your YAML file to set up a pipeline of deployments. Using phases, you can control the order of deployment to multiple web apps.

phases:

- phase: buildandtest
  queue: Hosted Linux Preview
  steps:

  # add steps here to build the app

  # the following will publish an artifact called drop
  - task: PublishBuildArtifacts@1

  - task: AzureRmWebAppDeployment@3
    inputs:
      azureSubscription: '<Test environment Azure service endpoint>'
      WebAppName: '<name of test environment web app>'

- phase: prod
  queue: Hosted Linux Preview
  dependsOn: buildandtest
  condition: succeeded()
  steps:

  # step to download the artifacts from the previous phase
  - task: DownloadBuildArtifacts@0
    inputs:
      artifactName: drop

  - task: AzureRmWebAppDeployment@3
    inputs:
      azureSubscription: '<Prod environment Azure service endpoint>'
      WebAppName: '<name of prod environment web app>'

Configuration changes

You may want to apply a specific configuration for your web app before deploying to it. This is particularly 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 then, you can change its value prior to deploying to each web app. You can do this either by applying a web config transformation or by substituting variables the in Web.config file. The following snippet shows an example of variable substitution.

phases:
- phase: test
  variables:
    connectionString: <test-environment connection string>
  steps:
  - task: AzureRmWebAppDeployment@3
    inputs:
      azureSubscription: '<Test environment Azure service endpoint>'
      WebAppName: '<name of test environment web app>'
      enableXmlVariableSubstitution: true

- phase: prod
  dependsOn: test
  variables:
    connectionString: <prod-environment connection string>
  steps:
  - task: AzureRmWebAppDeployment@3
    inputs:
      azureSubscription: '<Prod environment Azure service endpoint>'
      WebAppName: '<name of prod environment web app>'
      enableXmlVariableSubstitution: true

Deploying conditionally

You may choose to deploy only certain builds to the Azure web app. To do this, you can use one of these techniques:

  • Isolate the deployment steps into a separate phase, and add a condition to that phase.
  • Add a condition to the step.

    The following example shows how to use step conditions to deploy only those builds that originate from master branch.

- task: AzureRmWebAppDeployment@3
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
  inputs:
    azureSubscription: '<Azure service endpoint>'
    WebAppName: '<Name of web app>'

To learn more about conditions, see Specify conditions.

Deploy to a Government cloud or Azure Stack

Do this by creating a suitable service endpoint:

Deployment mechanisms

The examples above rely on our built-in Azure App Service Deploy task which provides simplified integration with Azure.

If you use a Windows agent, then 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, excluding files from the App_Data folder during deployment, and so on.

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

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 prior to or after deployment. This task can also be used to swap slots, install site extensions, or enable monitoring of the web app.

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

[ad_2]

source_link
https://www.asp.net