Facing issue access restriction rule for a web app using an Azure CLI command in a pipeline

Dattatray Giramkar 0 Reputation points
2023-06-24T07:39:34.66+00:00

Hi Team

When using the "az webapp config access-restriction add" command in an Azure pipeline to create an access restriction rule for a web app showing an below error.
User's image

Param(
    [Parameter(Mandatory=$true)]
    [string]$resourceGroupName,

    [Parameter(Mandatory=$true)]
    [string]$appServiceName,

    [Parameter(Mandatory=$true)]
    [string]$ruleName,

    [Parameter(Mandatory=$true)]
    [string]$serviceTag
)

# Retrieve the access restriction rules for the specified App Service
$accessRules = az webapp config access-restriction show --resource-group $resourceGroupName --name $appServiceName | ConvertFrom-Json

if ($LASTEXITCODE -ne 0) {
    throw "Error while fetching access-restriction"
}

# Check if an access restriction rule with the specified name exists
$existingRule = $accessRules.ipSecurityRestrictions | Where-Object { $_.name -eq $ruleName }

if (!$existingRule) {
    # Create a new access restriction rule if it doesn't exist
    Write-Output "Access restriction rule with name '$ruleName' does not exist. Creating a new rule..."
    az webapp config access-restriction add --resource-group $resourceGroupName --name $appServiceName --priority 100 --service-tag $serviceTag --rule-name $ruleName
} else {
    # Display a message indicating that the access restriction rule already exists
    Write-Output "Access restriction rule with name '$ruleName' already exists."
}

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
41,572 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.