az webapp list-runtimes - Powershell equivalent - azure

Does anyone know if there is any equivalent for the az cli command "az webapp list-runtimes" in PowerShell?
Thanks!

There is none I am aware of. However you can anyway fire az cmd from the same powershell session seamlessly if you are already into latest Az powershell.
$rt = az webapp list-runtimes # for linux, add --linux flag
# use $rt like a regular ps variable (would be array in this case)

Related

Creating webapps in Azure using AZ cli command

While creating webapps using Az cli in Azure, the command line have no option to mention the location parameter. However while creating from azure portal,there is a option where in we can select the region .
Following is the link to the command and the command itsel
https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest
az webapp create --name
--plan
--resource-group
[--assign-identity]
[--deployment-container-image-name]
[--deployment-local-git]
[--deployment-source-branch]
[--deployment-source-url]
[--docker-registry-server-password]
[--docker-registry-server-user]
[--https-only {false, true}]
[--multicontainer-config-file]
[--multicontainer-config-type {COMPOSE, KUBE}]
[--role]
[--runtime]
[--scope]
[--startup-file]
[--subnet]
[--tags]
[--vnet]
You can use az webapp up CLI command which has a location switch like
az webapp up -n MyUniqueAppName --runtime "java:11:Java SE:11" -l locationName
BTW, if you even don't specify the location while using az webapp create it will be default to the region of "Resource Group" or if you are specifying app service plan then that region would be in use
You can use this cmdlet for specifying the location while creating the web app in Azure:
New-AzwebApp [[-ResourceGroupName] <String>] [-Name] <String> [[-Location] <String>] ...
Of course, the next question will be some parameters like specifying runtime environment missing in the New-AzWebApp cmdlet, we need to use different combination of cmdlets for our requirement.
Please refer to one of these workarounds that shows how to choose the runtime environment when using the New-AzWebApp cmdlet.
Refer here for more information on New-AzWebApp cmdlet parameters.

How to enable "MySQL in App" in an App Service using the Azure CLI

I have created an App Service in Azure using the CLI. But, I cannot see any CLI options to enable "MySQL in App". I have checked here: https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest and see no mention of it.
What is the CLI to enable it? Or, failing that, if there is no CLI command, using PowerShell?
I know your question is related to az cli but I don't know if possible using that myself.
I can confirm however that the following works using PowerShell (Az module):
$app = Get-AzWebApp -ResourceGroupName <Resource Group Name> -Name <Web App Name>
$app.SiteConfig.LocalMySqlEnabled = $true
$app | Set-AzWebApp
Hope this helps until someone can confirm for az cli specifically.

Enable Health Check in a app service via CLI

Is there any way to enable health check via cli in azure app services? I see that we can modify some configurations but not an option to enable/disable the feature.
Thank you!
According to my test, we can enable/disable health check via changing the value of web config healthCheckPath. For more details, please refer to here.
For example(I test it via azure cloud shell)
a. Enable
az webapp config set -g <groupName> -n <web name> --generic-configurations '{"healthCheckPath": "/api/health/"}'
b.Disable
az webapp config set -g <groupName> -n <web name> --generic-configurations '{"healthCheckPath": ""}'
Thanks to #jim-xu answer I was able to get this working for our needs.
I did struggle trying to make syntax work in an existing PowerShell script with the string quotation marks and making it a variable. I thought I'd put that syntax here in case someone else is trying this via scripts not using bash.
# variables - these might be local or parameters from your function, etc..
$webAppName= "my-web-app"
$resourceGroupName = "my-resource-group"
$healthCheckPath = "/api/health/"
# the important part
$genericConfigurations = "{\""healthCheckPath\"": \""$healthCheckPath\""}"
az webapp config set --name $webAppName `
--resource-group $resourceGroupName `
--generic-configurations $genericConfigurations `
--output none
Yes I did attempt to be conscientious and read through Use Azure CLI effectively - Using quotation marks in values and it still wasn't clear to me.
I saw many other posts with users getting caught on this syntax; example 1, example 2, example 3.

Problem in Powershell with the --runtime command setting up Jenkins pipeline

I am trying to configure a Pipeline with Jenkins and deploying it to Azure. I am at the last step of a tutorial:
https://learn.microsoft.com/en-us/azure/jenkins/tutorial-jenkins-deploy-web-app-azure-app-service
This last step is as follows, i have to enter this in the Azure CLI:
az group create --name yourWebAppAzureResourceGroupName --location region
az appservice plan create --name appServicePlanName --resource-group rgname --is-linux
az webapp create --name webAppName --resource-group rgName --plan appServicePlanName --runtime "java|1.8|Tomcat|8.5"
The last command gives me the error:
'1.8' is not recognized as an internal or external command,
operable program or batch file.
So I thought maybe Tomcat is not installed on my Azure VM, which is a Linux machine. So I used the next tutorial to install Tomcat:
https://www.howtoforge.com/tutorial/how-to-install-apache-tomcat-8-5-on-ubuntu-16-04/
After this I tried to do the --runtime command again, but I still get the same error. I have no idea how to fix this. I hope someone can help me with this problem.
I tried to check the webapp list-runtimes and I get this list:
"java|1.8|Tomcat|8.5" is in here. I've tried all of the versions, but it did not work.
EDIT: It works in the Azure Cloud Shell, but then there is another error:
Linux Runtime 'java|1.8|Tomcat|8.5' is not supported.Please invoke 'list-runtimes' to cross check
I have tried all the runtime versions, but still this error. I have also tried it with double quotes
I bet you solved your problem already, but in case others find this and are using PowerShell to run Azure CLI commands. This is what worked for me.
The problem is in how PowerShell interprets the pipe, '|', character inside the --runtime parameter, when evaluating the whole line.
Add the --% to be beginning of the command to turn off PowerShell evaluation of expressions, as suggested in the code block here.
Note: this will also stop PowerShell from evaluating any variables inside the command. What you can do is move the --runtime to the end of the line to get around this problem, e.g. like this
az webapp create -g $rg -p $appPlanName -n $appName --deployment-local-git --% --runtime "DOTNETCORE|3.0"
ok, i got it, that list is for windows webapp, not linux. for linux use:
az webapp list-runtimes --linux
so working solution:
az webapp create --name yourWebAppName --resource-group yourWebAppAzureResourceGroupName --plan yourLinuxAppServicePlanName --runtime "TOMCAT|8.5-jre8"

Azure Cli how to change subscription default

I have 3 subscription in my Azure Account, I need to change the default subscription. When i Run the command:
azure account list
I have this output:
I have tried to change the default or current subscription on this way, with no results...
azure config set subscription {{MyIdSubscription}}
Any ideas? Thanks.
For Azure CLI 2.0 (preview) I had to use
az account set --subscription <name or id>
Please try the following:
azure account set -s {Subscription Id}
That should change the subscription.
1. List all the subscriptions you have
az account list --output table
Name CloudName SubscriptionId State IsDefault
--------------- ------------ ---------------- --------- ----------
AssociateProd AzureCloud xxxxxxxxxxxx Enabled False
2. Pick the subscription you want and use it in the command below.
az account set --subscription <subscription_id>
Use id (subscription id) that is GUID, which will be listed when you did az login
And then execute the below command..
az account set --subscription fffde5cb-cccc-aaaa-eee-457c3292608e
Try in this way.it worked for me to set Azure PowerShell to a specific Azure Subscription
Set-AzContext -SubscriptionId "t666-e251-49ce-a1cd-5c3144"
An important tip!
Be careful mixing Azure Shell and Powershell - eg. "az login" and "Connect-AzAccount"
If you use "az login" it will not reflect on commands like Get-AzContext.
So if you have powershell scripts that depend on Get-AzContext they'll fail.
Azure CLI latest (2.39.0):
az account set (--name or -n) <name>
az account set (--subscription or -s) <id>
I have created a wrapper around the Azure-CLI for this in a PiP Package, with colors.
pip install azure-account-switcher
note: it's dependent on azure-cli which downloads a lot of dependencies. So you should install in environment with azure-cli already present.

Resources