How you do use Secrets in a Connection String Azure Release Pipeline - Using Azure App Service Settings Task

Viewed 362

I am using Azure App Service Settings task in a release pipeline for a web app. I need to set the connection string.

According to the help icon it expects JSON syntax

 {
    "name": "key1",
    "value": "valueabcd",
    "type": "MySql",
    "slotSetting": false
   }

I would like pull the "value" from either a Variable Group that I have linked to Azure Key Vault, or from KeyVault or even just a pipeline variable. I just want it to be secure.

The problem I am running into is how to pass a variable into the JSON if its a secret. If I do something like this

   {
    "name": "ConnectionStringName",
    "value": "$(DBConnectionString)",
    "type": "SQLAzure",
    "slotSetting": false
   }

Then the connection string is literally $(DBConnectionString). You cant remove the quotes because then its not proper JSON. It it related to the fact that its a secret because it works fine with regular variables. I have read a few articles about how secrets are used differntly, but have not been able to apply them what I am doing.

I am including a screenshot to help explain where I am seeing this.

Screenshot from Azure Release Pipeline Task

2 Answers

I ran release pipeline with this:

[
        {
          "name": "MysqlCredentials",
          "value": "$(MySQl_ConnectionString)",
          "type": "MySql",
          "slotSetting": false
        }
      ]

enter image description here

Having variable set in Variables:

enter image description here

And then I got:

enter image description here

So if you don't have it replaced it could mean that you don't have variable defined.

I made it a secret:

enter image description here

And it still works:

enter image description here

I figured out a solution that worked in my scenario. I put the connection string in Vault and added the Azure Key Vault task right before my Azure App Service Settings task and then the standard variable sub worked.

Related