Microsoft Azure Documentation

Deploy Code to Azure App Service

This document provides a comprehensive guide on how to deploy your application code to Azure App Service, a fully managed platform for building, deploying, and scaling web apps and APIs.

Introduction to Deployment Options

Azure App Service supports a variety of deployment methods, catering to different development workflows and preferences. You can deploy code from local sources, cloud repositories, or automated CI/CD pipelines.

1. Deploying from a Local Git Repository

If you are using Git for version control locally, you can configure App Service to be a remote repository. This allows you to push your code directly to App Service.

  1. In the Azure portal, navigate to your App Service.
  2. Under "Deployment", select "Deployment Center".
  3. Choose "Local Git" as your source.
  4. Follow the instructions to set up your Git credentials and configure the local Git remote.
  5. Use the following commands in your local Git Bash or terminal:
    git remote add azure <Your-App-Service-Git-URL>
    git push azure main

2. Deploying from GitHub or Azure Repos

Integrate directly with your GitHub or Azure Repos repositories for continuous deployment. App Service can monitor your repository and automatically deploy new commits.

GitHub Actions Example

Configure a GitHub Actions workflow to build and deploy your application. Here's a simplified example for Node.js:

name: Node.js Deploy to Azure

on:
  push:
    branches: [ main ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Node.js version
      uses: actions/setup-node@v1
      with:
        node-version: '14.x'
    - name: npm install, build, and test
      run: |
        npm install
        npm run build --if-present
        npm test
    - name: Azure WebApp Deploy
      uses: azure/webapps-deploy@v2
      with:
        app-name: 'YourAppName'
        package: '.'
        slot-name: 'production'
      env:
        AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}

To set up this integration in the Azure portal:

  1. Navigate to your App Service and select "Deployment Center".
  2. Choose "GitHub" or "Azure Repos" as your source.
  3. Authorize the connection to your repository and select the branch to deploy from.
  4. Configure build settings if necessary.

3. Deploying using Zip Deploy

For scenarios where you have a pre-built deployment package (e.g., a ZIP archive), you can use the Zip Deploy feature.

4. Continuous Deployment from Cloud Sources

App Service offers built-in integrations with popular cloud storage services like Dropbox and OneDrive. This allows you to synchronize your deployment package directly from these services.

Important: Ensure your application is built for the correct operating system and architecture of your App Service plan (Windows or Linux).

Deployment Slots

Deployment slots are a powerful feature for managing your deployments. They allow you to deploy your application to a staging environment, test it thoroughly, and then swap it into production with zero downtime.

Troubleshooting Deployments

If you encounter issues during deployment, consider the following:

For detailed troubleshooting steps and common issues, refer to the official Azure App Service troubleshooting guides.