skip to Main Content

Issue

We have a function app in Azure, and from Azure DevOps, through a classic release pipeline, we deploy the function and app settings.

One of those app settings has a value "abcrndefrnghirn…"

However, when we deploy this app setting from DevOps, the value in Azure portal becomes
"abc\r\ndef\r\nghi\r\n…"
Does anyone know why, and how to avoid this additional being added please?

Here’s an overview of the task group tasks:
enter image description here

What I noticed

In the Azure portal UI, the value of the app setting shows as it was provided in DevOps. Thus, with single where needed.

However, in the underlying json, via Advanced Edit on the app settings, I see that the actual (real/used) value has double characters.

What I tried

  • I tried using ` instead of . This didn’t help.
  • If I provide the correct value, with single via Advanced Edit, the sftp connection that I’m trying to make works fine. However, we don’t want to do this manually.

Edit after key vault integration

I noticed that when I use (backtick)n instead of rn I can force PowerShell to create new lines. With rn this doesn’t work.

PowerShell ISE new line ok

However, when I store the private key in the key vault, containing `n for new lines, this doesn’t work via the function.

function result new line not ok

n in the key vault secret value also does not work.

PS. I know I should not be outputting the private key value, but I’m doing this now for testing purposes only.

2

Answers


  1. Chosen as BEST ANSWER

    After implementing the key vault structure as suggested by Rui Jarimba, I had to update the PowerShell code of the function just a little to make this work.

    Basically, the function retrieves the value of the secret from the key vault as plain text. To work around it I added a 'replace'.

    Example where n is used in the key vault secret value:

    $keystring = $env:sftpprivatekey 
    $privatekey = $keystring.Replace('n', "`n") # keystring is retrieved from key vault as plain text, n is treated as literal character. A 'replace' helps to enforce the escape sequence for newline character.
    

    The sFTP connection could then be made via:

    $SFTPSession  = New-SFTPSession  -Computer $computer -Credential $credential -Port $port -KeyString $privatekey -AcceptKey:$true -Verbose
    

  2. You may use Azure Keyvault to store multiline settings. Then create a reference from the setting:

    @Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret)
    

    Additionally, you may use PowerShell to set the variable:

    Update-AzFunctionAppSetting -Name $functionName -ResourceGroupName $functionAppResGroup -AppSetting @{$appsettingname = "true`nfalse"} -Force
    

    The result:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search