Skip to the content.

Lab: Reusable Workflow - Azure App Service Deploy

Objective

In this lab, you will learn how to create a reusable GitHub Actions workflow for deploying an ASP.NET Web App to Azure. This reusable workflow will allow you to standardize the deployment process across multiple workflows or projects by passing in parameters for the web app name and package path.

Prerequisites

  1. GitHub Repository: A GitHub repository to store the workflow YAML files and use GitHub Actions.

Step 1: Create the Reusable Workflow File

  1. Navigate to the .github/workflows directory of your repository.
  2. Create a new file named reusable-workflow-azure-webapp-deploy.yml.

  3. Define the reusable workflow: Paste the following YAML content into the reusable-workflow-azure-webapp-deploy.yml file. This workflow is responsible for deploying the web app to Azure.
name: Reusable Workflow Azure Web App Deploy

on:
  workflow_call:
    inputs:
      AZURE_WEBAPP_PACKAGE_PATH:
        required: true
        type: string
      AZURE_WEBAPP_NAME:
        required: true
        type: string
    secrets:
      AZURE_SERVICE_PRINCIPAL:
        required: true

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: webapp
          path: $

      - name: Azure Login
        uses: azure/login@v2
        with:
          creds: $

      - name: Deploy to Azure WebApp
        uses: azure/webapps-deploy@v2
        with:
          app-name: $
          package: $

Breakdown of the workflow


Summary

Congratulations! You have created a shared GitHub Actions workflow for deploying an ASP.NET Web App to Azure. This shared workflow can be reused across multiple workflows or projects by passing in parameters for the web app name and package path.