Automating Multi-Client Deployments in Azure App Service with CI/CD Pipelines

Yaswanth RYaswanth R
3 min read

Introduction

In many enterprise projects, multiple clients often require customized deployments of the same application with slight variations in configurations. Traditionally, manually deploying these applications for each client in a production environment can be time-consuming and prone to human errors. To solve this, I have automated the deployment process using Azure App Service and CI/CD pipelines, significantly improving efficiency and reliability.

Problem Statement

Previously, for each client request, I had to manually deploy the application in Azure App Service, ensuring the required configurations were in place. This process was repetitive and inefficient. To streamline the workflow, I created different branches for different clients and developed a pipeline that automates deployments based on client-specific needs.

Solution: CICD Deployment Pipeline

To automate and simplify the deployment process, I set up a robust pipeline that allows triggering deployments effortlessly. The pipeline updates the necessary configurations and ensures the application is deployed in the correct slot with minimal manual intervention.

Key Features of the Pipeline

  1. Client-Specific Branching

  • Each client has a dedicated branch in the repository.

  • When a client requests a deployment, the corresponding branch pipeline is triggered.

  • The pipeline updates the ASPNET_ENVIRONMENT variable according to the client.

  • A appsettings.clientname.json file contains client-specific deployment URLs.

  1. Two Deployment Strategies

    I have implemented two methods to deploy applications to Azure App Service:

    Method 1: Pushing Code to the Azure SCM Repository

    • Each App Service slot in Azure has an SCM (Source Control Management) repository.

    • The pipeline retrieves the Azure SCM repo link along with its username and password.

    • The code is pushed to the SCM repository.

    • Azure App Service automatically handles the build and publish process.

Sample Pipeline code for SCM Repository Deployment:

    stages:          
      - admin
      - webapi

    workflow:
      rules:
        - if: '$CI_COMMIT_REF_NAME == "generated"'

    admin-deploy:       
      stage: admin
      variables:
        Appservice_USER: $APPSERVICE_USER
        Appservice_PASSWORD: $APPSERVICE_PASS
        ADMIN_REPO_URL: "mahatscm-webapp.scm.azurewebsites.net:443/mahatscm.git"
      script:
        - git config --global user.name "GitLab CICD"
        - git config --global user.email "mahatdevblu@gmail.com"
        - echo "Cloning the Azure App Service repository for Admin slot..."
        - git clone https://$Appservice_USER:$Appservice_PASSWORD@$ADMIN_REPO_URL admin-repo
        - cd admin-repo
        - rm -rf Admin
        - rm -rf ShopCoreEnterprise.Models
        - cp -r /builds/tdevstaging/ShopCoreEnterprise/webapp/Admin ./Admin
        - cp -r /builds/tdevstaging/ShopCoreEnterprise/webapp/ShopCoreEnterprise.Models ./ShopCoreEnterprise.Models
        - ls -al
        - git add .
        - git commit -m "Deploy admin from CICD"
        - git push origin master
      only:
        - generated

Method 2: Deploying via Azure Publish Profile

  • The publish profile of the respective Azure App Service slot is obtained.

  • The application code is deployed directly into the slot using this profile.

  • This method bypasses the need for an external repository and ensures a direct deployment.

Sample Pipeline code for Publish Profile Deployment:

admin-deploy-publish-profile:
  stage: admin
  script:
    - echo "Deploying Admin using Azure Publish Profile..."
    - az webapp deployment source config-zip --resource-group myResourceGroup --name myAppService --src /builds/tdevstaging/ShopCoreEnterprise/webapp/Admin.zip
  only:
    - generated
  1. Automated Deployment Scheduling with Crontabs

    • Clients request deployments at different times.

    • To accommodate this, the pipeline integrates crontab-based scheduling.

    • This ensures that deployments are triggered at predefined times, reducing manual intervention.

Sample Crontab Integration for Scheduled Deployment:

scheduled-deploy:
  stage: admin
  script:
    - echo "Triggering scheduled deployment..."
    - curl -X POST -F token=$CI_JOB_TOKEN -F ref=generated https://gitlab.com/api/v4/projects/:id/trigger/pipeline
  only:
    - schedules

Benefits of this CICD Deployment Pipeline

  • Time-Efficient: Eliminates the need for manual deployments.

  • Error-Free: Ensures configurations are correctly set for each client.

  • Scalable: Easily extendable to new clients by adding new branches and slots.

  • Flexible: Supports both real-time and scheduled deployments.

Conclusion

With this automated deployment pipeline, I have significantly improved the deployment process for multi-client applications. By leveraging Azure App Service slots, CI/CD pipelines, and automated scheduling, this solution eliminates manual interventions and enhances deployment efficiency. Organizations facing similar challenges can adopt this approach to streamline their multi-client deployments effortlessly.

0
Subscribe to my newsletter

Read articles from Yaswanth R directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yaswanth R
Yaswanth R

As a final-year Computer Science and Engineering student at Sri Eshwar College of Engineering, I am deeply passionate about technology and innovation. My academic journey has been marked by consistent performance, achieving a CGPA of 8.1, and by actively participating in hackathons and expos, including securing 1st place in the MiniProject Expo Hackathon. Beyond academics, I have a strong interest in cloud computing, DevOps methodologies, and automation tools. I have honed my skills through internships and real-world projects, including my role as a DevOps Intern at Mahat Labs Pvt. Ltd. During this experience, I automated CI/CD pipelines for .NET and Flutter applications using GitLab CI/CD, containerized microservices with Docker, and deployed them to Kubernetes clusters built with kubeadm. I also integrated SonarQube into CI/CD workflows for code quality analysis and developed custom monitoring scripts to enhance infrastructure reliability. My hands-on experience extends to tools like Jenkins, Proxmox, and AWS, where I have successfully modernized deployment workflows and streamlined software delivery processes.