You can use Azure Command Line Interface with PowerShell to create infrastructure as code (IaC) scripts, for implementing deployment of resources in Azure platform services. When you try to create a web app in Azure with run time specified with Azure CLI in PowerShell, | symbol used in runtime specification causes issues as it is trying to do a pipe operation in PowerShell. Let’s look at the issue and how to get it resolved in PowerShell and Azure CLI based IaC scripts.
The Issue
When the script below executed, $nodeRuntime is set as node|6.12 the script fail with issue shown in below image.
$webAppPricePlan = az appservice plan show -n $azureFunctionsAppPlanName -g $sharedResourceGroupName | ConvertFrom-Json
Write-Host ("Web App " + $name + " is not found. Creating it...")
az webapp create -n $name -g $resourceGroupName -p ($webAppPricePlan.id) -r $nodeRuntime
'6.12' is not recognized as an internal or external command, operable program or batch file.
How to Resolve
To resolve this issue, we can use --% as escape to | symbol. However, to run this in a PowerShell script with variables, we have to copy it as an evaluated expression. The execute it via Invoke-Expression. If the script is getting executed with hardcoded values instead of variable usage you do not have to use Invoke-Expression.
$exp = 'az webapp create -n ' + $name + ' -g ' + $resourceGroupName + ' -p ' + ($webAppPricePlan.id) + ' --% -r ' + '"' + $nodeRuntime + '"'
Invoke-Expression($exp)
Once this is resolved the script can be used in Azure Pipelines to create node web app resources in Azure.
Thursday 19 December 2019
Resolving Issues with | Symbol in PowerShell While Creating Node Web App in Azure CLI
Subscribe to:
Post Comments (Atom)
Popular Posts
-
In Azure DevOps YAML pipelines there are several functions available for you to use. replace is such a useful function, which you can use t...
-
Adding Azure Container Registry (ACR) service connection to Azure DevOps is really simple as described in " Create Service Connection ...
-
We have discueed, that we have to use an environment variable to handle input parameter default values, if we are using trigger for workflo...
-
Some times a silly mistake can waste lot of time of a developer. The exception “System.IO.IOException: The response ended prematurely.” whil...
-
Sometimes you may need to edit files especially the web.config or appsettings.json files after deploying your application to Azure App Servi...
No comments:
Post a Comment