Open In App

Microsoft Azure – Testing in Production Sites Feature using PowerShell

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to add logic to your testing and production sites with PowerShell. Now, if you wanted to do this programmatically via a PowerShell script follow the below-given steps.

Implementation:

Follow the below steps to add logic to testing production sites with PowerShell:

Step 1: Head over to the Azure CLI website and we can install the PowerShell modules that allow us to programmatically manage our resources inside of the cloud. 

Step 2: Now, as we already have it installed. We are going to open a local PowerShell instance in our machine and using the script we are going to set our staging slot to receive 90% of the traffic instead of 50%.

$siteName="MyQuizDemo"
$ruleList=New-Object-TypeName System.Collections.Generic.List[Microsoft.WindowsAzure.Commands.Utilities.Web
$rule=New-Object-TypeName Microsoft.WindowsAzure>Commands.Utilities.Websites.Services.WebEntities.RampUpRule
$rule.Name="stage"
$rule.ActionHostName="$siteName-Staging.Azurewebsites.net"
$rule.ReroutePerce3ntage=90
$rulesList.Add($rule)
Set-AzureWebsite-RoutingRules $ruleList -Name $siteName -slot production

Now that’s complete, we will go back over to the Azure Portal. What we need to do is just refresh this page.

Step 3: When we head back over to the testing and production section we shall see how our values have changed to 90% to staging and 10% to production. 

Step 4:Now, if we want to have more fine-grained control over how these changes happen. We will head over to a second PowerShell tab and have a second script there. What it does is that every 60 minutes it’ll increase the amount of traffic that goes over to our staging slot by 5%. So, let us go ahead and run this. 

$siteName="MyQuizDemo"
$rule1=New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.RampUpRule
$rule1.ActionHostName="$siteName-Staging.Azurewebsites.net"
$rule1.REroutePercentage=5:
$rule1.Name="stage"
$rule1.ChangeIntervalInMinutes=60;
$rule1.ChangeStep=5:
$rule1.MinReRoutePercentage=5;
$rule1.MaxReroutePercentage=50;
$rule1.ChangeDecisionCallbackUrl=$null
Set-AzureWebsite $siteName -Slot Production -RoutingRules $rule1

That script is complete and just like before, we are going to refresh this page quickly. Now that we’ve run that script every 60 seconds we’ll slowly see more and more traffic heading over to our staging slot.

And that’s how we can control the azure app servers routing rules for our staging slots using PowerShell.


Last Updated : 03 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads