Skip to main content

Publish EmpowerID Microservice to Azure Using PowerShell

After developing and building a microservice, you can deploy it to Azure App Service using a PowerShell script. This script uses the Azure App Service publish profile to authenticate and deploy the microservice package via ZIP deployment.

Prerequisites

Before deploying a microservice, ensure you have:

  • Microservice ZIP file - Located in the ..\\EmpowerID\\WFS\\_microservices folder after building your project in Visual Studio
  • Azure App Service - Created and configured in your Azure subscription
  • Publish profile - Downloaded from your Azure App Service
  • PowerShell - Administrative access to run PowerShell scripts
note

The microservice ZIP file is automatically created when you build your project in Visual Studio. The file name matches your microservice project name.

Download the Publish Profile

  1. Log into the Azure Portal.
  2. Navigate to your App Service.
  3. Click Get publish profile in the toolbar.
  4. Save the .PublishSettings file to a known location on your computer.

This file contains the credentials and endpoints needed for deployment.

Create the Deployment Script

  1. Open a text editor.

  2. Copy the following PowerShell script:

    param(
    $pubProfileFilePath
    ,$zipFilePath
    )

    # Stop execution on any error
    $ErrorActionPreference = "Stop"

    # Load and parse the publish profile XML
    $pubProfile = [xml](gc $pubProfileFilePath)

    # Extract the ZIP deploy profile settings
    $zipPubProfile = $pubProfile.publishData.publishProfile | where { $_.publishMethod -eq "zipdeploy" }

    # Set user agent for the deployment request
    $userAgent = "powershell/1.0"

    # Create authentication header using publish profile credentials
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $zipPubProfile.userName, $zipPubProfile.userPWD)))

    # Construct deployment URLs
    $zipdeployUrl = "https://$($zipPubProfile.publishUrl)/api/zipdeploy"
    $deploymentsUrl = "https://$($zipPubProfile.publishUrl)/api/deployments"

    # Deploy the ZIP file to the App Service
    Invoke-RestMethod -Uri $zipdeployUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method Post -InFile $zipFilePath

    # Query deployment status
    Invoke-RestMethod -Uri $deploymentsUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method Get
  3. Save the file as zipdeploy_appService.ps1 in a convenient location.

What the Script Does

The script performs these operations:

  1. Loads the publish profile - Reads the XML publish settings file
  2. Extracts credentials - Gets the username and password for ZIP deployment
  3. Creates authorization header - Encodes credentials in Base64 format
  4. Deploys the package - POSTs the ZIP file to the App Service ZIP deploy endpoint
  5. Queries status - Retrieves deployment information to confirm success

The script uses the Kudu ZIP deployment API, which is the same mechanism used by Visual Studio's publish feature.

Deploy the Microservice

  1. Open PowerShell as Administrator.

  2. Navigate to the directory where you saved the script:

    cd C:\path\to\script\directory
  3. Execute the script with the required parameters:

    .\zipdeploy_appService.ps1 -pubProfileFilePath "C:\path\to\your-app-service.PublishSettings" -zipFilePath "C:\path\to\EmpowerID\WFS\_microservices\YourMicroservice.zip"
  4. Wait for the deployment to complete.

    Example command:

    .\zipdeploy_appService.ps1 -pubProfileFilePath "C:\Downloads\myapp.PublishSettings" -zipFilePath "C:\EmpowerID\WFS\_microservices\MySCIMService.zip"

    PowerShell Deployment Command

Verify Deployment

After the script completes:

  1. Navigate to your App Service in the Azure Portal.
  2. Click Deployment Center in the left menu.
  3. Verify the deployment appears in the deployment history.
  4. Check the deployment status shows as successful.

Alternatively, navigate to your microservice endpoint in a browser to verify it's responding.