Azure slots :Can i swap only app settings/connection strings?

Viewed 370

Is there a way we can swap only app settings/connectionstrings but not code from Azure App Service slot using azure DevOps pipeline or Azure CLI?

2 Answers

You can try this,

Step 1 : Create two separated environments in a release as per your needs!

Step 2 : Create a variable with the same name as your connection string name in your web.config, one scoped for staging environment and the other for production.

Step 3 : Add a Deploy Azure App Service task to each environment.

Then you could use the File transformation and substitution options and mark to make the transformation. Take a look at XML Transformation and JSON transformation

We are trying to get connectionstring directly from the slot and swap it to prod but not code.

As far as I know, you can use Azure CLI to achieve it.

Appsettings: az webapp config appsettings

ConnectString: az webapp config connection-string

You could use Azure CLI to list appsettings/connectionstring. Then you could use the set command to pass the values to the slot.

Here is my sample(In Azure Devops Azure CLI Task):

$appsettings=az webapp config appsettings list --name webappname -g  ResourcesGroupName   --slot  slotname

$appsettings| Out-File "$(System.DefaultWorkingDirectory)\appsettings.json" 

az webapp config appsettings set -g ResourcesGroupName   -n webappname  --settings -slot slotname "@$(System.DefaultWorkingDirectory)\appsettings.json"

$connectstring=az webapp config connection-string list --name webappname -g  ResourcesGroupName   --slot  slotname

$test = $connectstring | ConvertFrom-Json


$test | Select-Object -Property Name,slotSetting ,type,Value | ForEach-Object {
    Write-Host $_.Name $_.Value 
    $msg =   $_.Name , $_.Value   -join '='
    echo    $msg 

    az webapp config connection-string set --name webappname -g  ResourcesGroupName   -slot slotname -t mysql --settings  $msg 

}

Note: Here is an known issue about the az webapp config connection-string set. It couldn't support to set files in settings parameter for the time being.

Related