I'm trying to deploy my configuration settings using Azure CLI step in my release pipeline.
There are multiple commands in it that I need to run which looks like this.
- *az webapp config settings set -g resourceGroupName -n WebAppName
--settings somekey=somevalue*
Note that There is a resourcegroupname and webappname that are present in it.
How Can I create a Variable for those two values and use them in my CLI.
I have tried adding them to the arguments but it didn't work.
Getting below error
validation error: Parameter 'resource_group_name' must conform to the following pattern: '^[-\\w\\._\\(\\)]+[^\\.]$'.
The reason being that I have 30 odd values and I need to create those variables for webapp which is present in multiple resource groups, So that I can simply swap the name of resource group and run the CLI.
You need to define variable in your pipeline and then use them in Azure Cli step.
So if you have variable named ResourceGroup you should have
az webapp config settings set -g $(ResourceGroup) -n WebAppName --settings somekey=somevalue
You can also create variable group and reuse it across your pipelines.
Related
I am using Azure CLI to use the azure. I am trying to create a staticwebapp and later try to add the configuration from CLI.
I tried to run this
az staticwebapp appsettings set -n appname --setting-names MONGO_CONNECTION_STRING="mongodb+srv://anirudha:testing#cluster4340.v45343.mongodb.net/?retryWrites=true&w=majority"
I am getting error
'w' is not recognized as an internal or external command,
operable program or batch file.
I go to portal and seen before &w=majority is added into configuration but this part is not added after &.
I tried to put singlequote and key=("val") but none of them working for me. I found this in azure app config github repo.
Anyone have idea how to make it work from CLI
--setting-names property accepts the app settings in 'key=value' format as mentioned here in this documentation of az staticwebapp app settings set cmdlet.
You need to change the above shared cmdlet to the below:
az staticwebapp appsettings set -n <staticWebAppName> --setting-names 'MONGO_CONNECTION_STRING=<AppsettingValue>'
I have tested this and it is working fine from my end Here is the sample output screenshot for your reference:
Updated Answer:
Alternatively, you can use this PowerShell cmdlet
(New-AzStaticWebAppSetting) to update the app settings of the static web app
New-AzStaticWebAppSetting -ResourceGroupName resourceGroup -Name staticweb01 -AppSetting #{'function01' = 'value01'; 'function02' = 'value02' }
I tried to pull yaml from my running AKS, which kubectl options I can run in order to pull full yaml file form running azure AKS , need it for only 1 AKS Name ?
full yaml file means - the same as if I go on azure portal and click and go inside of my AKS, then on the left pane I can click: "export template" , but it is in json, I need the same in yaml
In the following answer I have referenced Azure CLI commands. You can find installation instructions here.
If you want the managedCluster object of an AKS cluster in yaml format please run:
az aks show -g $ResourceGroupName -n $AKSClusterName -o yaml
If you want specific Kubernetes resource(s) in a yaml format
First run
az aks get-credentials -g $ResourceGroupName -n $AKSClusterName
to get the access credentials for the AKS cluster and merge them into the kubeconfig file.
Now you can run:
kubectl get $resource-type $resource-name -n $namespace -o yaml
Please replace $resource-type with the correct Kubernetes resource type (e.g. pod, node, deployment, service, replicaset, ingress etc.) and $resource-name with the corresponding desired resource name. If you want to get a list of all resources of $resource-type you can ignore specifying $resource-name. If you want to list resources of $resource-type in all namespaces please replace -n $namespace with --all-namespaces
For example, if you want to get the list of all pods in the namespace development in yaml format then, you should run:
kubectl get pods -n development -o yaml
References:
https://learn.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
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.
I am using Azure CLI azure-devops extension to manage my projects and git repositories in dev.azure.com.
az extension add --name azure-devops
To make code more readable and configurable I would like to use: (it does not matter if the values are between quotation marks or not)
az devops configure --defaults organization=https://dev.azure.com/myname
az devops configure --defaults project=f514a982-...
Those commands executed without error (powershell) but it seems they has no effect on the following commands.
For example
az repos list # lists an other project's repos, not the required f514a982
However executing
az repos list --project f514a982....
gives the expected result.
Missing I something or is this a bug?
Actually I figured it out, hopefully spares time someone in the future:
There is a --detect parameter which is on by default and if it is on then overrules the --defaults settings.
So if you run anywhere the command under a git repo folder tree and you do not explicitly use the --detect off, it will use that devops project (as default) which that git repo belongs to regardless of the previously executed az devops configure --defaults command
I get this error in windows CMD "stat: path too long for Windows" whenever I execute this command below in my azure cli in windows CMD.
az group deployment create -g "testacsengine" --template-file azuredeploy.json --parameters #azuredeploy.parameters.json
In windows, if you already install the Azure CLI model, you can execute the CLI command in CMD or Windows PowerShell ISE.
For the deployment of Azure template, you can just use the command az group deployment create -g "charlesTest" --template-file template.json in the directory of your template.
Or use the absolute path like this az group deployment create -g "charlesTest" --template-file D:\template.json. Of curse, you need to get authentication with the command az login first.
If you still get the error when you do this, the error must be inside your template. You should check your template correctly.
For more details about template deployment, see az group deployment create.