Azure-cli: webapp:How to 'set' multiple appsettings in the same command?

Created on 7 Sep 2018  ·  15Comments  ·  Source: Azure/azure-cli

Using az functionapp config appsettings set, is there a way to set multiple appsettings in one command?

For example, for several Javascript functions I want to set FUNCTIONS_EXTENSION_VERSION, APPINSIGHTS_INSTRUMENTATIONKEY and WEBSITE_NODE_DEFAULT_VERSION at the same time, if possible. Now I have re-run the command for each setting, which takes a small performance hit during CI/CD.

It isn't a showstopper, but it would be elegant to be able to send simply one update command to Azure, using the CLI.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

question

Most helpful comment

Please can this method of passing settings via Json be fully documented.

All 15 comments

Supported through: --settings : Space-separated app settings in a format of <name>=<value>.

This is OK - but it'd be lovely if we could pass a yaml or json file with settings instead?

@IanIsFluent, yes you can

az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings @moreSettings.json

@yugangw-msft How'd I miss this in the docs!? 🤦‍♂️ Thanks!

How do we set a value for a key which contains "." dots in it, for e.g.:-

az webapp config appsettings set -n $appName -g $resourceGroupName --settings org.apache.tomcat.websocket.DISABLE_BUILTIN_EXTENSIONS =" true"

I am unable to set value here event with double quotes, single quotes

@ketaanhshah in case this is a nested structure than please try using colon ":" instead of dot ".", according to suggestion from Darren Neimke e.g.:

org:apache:tomcat:websocket:DISABLE_BUILTIN_EXTENSIONS=true

@IanIsFluent, yes you can

az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings @moreSettings.json

@yugangw-msft @IanIsFluent What is the right structure of the json file to do multiple settings?

How do we set a value for a key which contains "." dots in it, for e.g.:-

az webapp config appsettings set -n $appName -g $resourceGroupName --settings org.apache.tomcat.websocket.DISABLE_BUILTIN_EXTENSIONS =" true"

I am unable to set value here event with double quotes, single quotes

@ketaanhshah Like this

az functionapp config appsettings set --name $functionAppName --resource-group $rg --settings "tes.t=value2" "test.1=value3" --subscription $subscriptionName

@ajklotz

The content of the json file should be
[
{
"name": "Setting1",
"slotSetting": false,
"value": "Setting1value"
},
{
"name": "Setting2",
"slotSetting": false,
"value": "Setting2value"
}
]

In case someone else also struggled like me, the json file name should be in double-quotes:

az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings "@moreSettings.json"

Please can this method of passing settings via Json be fully documented.

@IanIsFluent, yes you can

az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings @moreSettings.json

What does the @ symbol do in this case? I’m looking to implement this in Azure DevOps using the classic editor and I have a bash script that I’m currently executing that just reads a key value pair file. Will the CLI automatically read the JSON file when prefixed with @? Or should I include the cat function in the bash script?

@singhramkumar Did you get it properly handle slotsettings? No matter what I do all settings are written as slot settings when I use the JSON file

@singhramkumar Did you get it properly handle slotsettings? No matter what I do all settings are written as slot settings when I use the JSON file

Hey, I think what you are looking for is the following

az webapp config appsettings set \
  -g MyResourceGroup \
  -n MyUniqueApp
  --settings "@appsettings.json" \
  --slot-settings "@slotsettings.json"

And then appsettings.json and slotsettings.json should in be in format of

[
  { "name": "SettingName", "value": "Setting Value" }
]

The formatting of the command line - with --settings taking multiple arguments each wrapped in double-quotes - feels somewhat clunky, and seems incompatible with powershell variables.

If I have my configuration in a reusable hash-table variable:

PS > $config=@{
    "FUNCTIONS_WORKER_RUNTIME" = "dotnet";
    "FUNCTIONS_EXTENSION_VERSION" = "~3";
    "WEBSITE_VNET_ROUTE_ALL" = "1";
};

...I wouldn't know how to properly format the variable so that it can be appended to the 'az' command.

I tried unwrapped and quoting it with something like:

PS > $settings = [System.String]::Join(' ', $($config.Keys | % { """$_=$($config[$_])""" }) );
PS > $settings
"FUNCTIONS_EXTENSION_VERSION=~3" "FUNCTIONS_WORKER_RUNTIME=dotnet" "WEBSITE_VNET_ROUTE_ALL=1"

And even though the command itself looks _exactly_ right, the quotes are misinterpreted and I end up with a single appsetting
FUNCTIONS_WORKER_RUNTIME that has the value dotnet FUNCTIONS_EXTENSION_VERSION=~3 WEBSITE_VNET_ROUTE_ALL=1

Was this page helpful?
0 / 5 - 0 ratings