1

Is there a way to deploy complete variable group variables to Azure Function app settings using Yaml.

Below is the yaml code and how I am deploying variable :-

variables:
- group: MyDevVariable #This is my variable group name

#Place where I am referring my variables from variable groups 
   deploy:
        steps:
            -task: AzureFunctionApp@1
             inputs:
               appSetting: '-Key1 $(Key1) -Key2 $(Key2)' #Key1 and Key2 are stored in variable group.

but if I have many variables, I have to mentions every variable in appSettings as key $(key).

So Is there a way to deploying all my variables from variable group to azure function app setting.

Any response is greatly appreciated. Thanks in advance.

Krishna
  • 135
  • 1
  • 9
  • Agree with WaitingForGuacamole, there is no such out of box way to do this. You could try below answer, this seems a great idea. – Leo Liu Mar 04 '21 at 03:04

1 Answers1

1

I don't believe that you can iterate the group's variables in the YAML directly. There's no syntax to reach into the group from what I've seen. What you can do is to write a script that gets the variables out of the group (if you have Azure CLI installed on the agent) and then reference it later:

deploy:
  steps:
  - task: AzureCLI@2
    inputs:
      name: GetSettings
      azureSubscription: Your Service Connection
      scriptType: ps
      scriptLocation: inlineScript
      inlineScript: |
        $env:AZURE_DEVOPS_EXT_PAT = '$(System.AccessToken)'
        $groupVars = (az pipelines variable-group list --group-name "My Group Name") | ConvertFrom-JSON
        $settingsList = ""
        $groupVars.variables.PSObject.Properties | ForEach-Object {
            $settingsList += "-$($_.Name) `"$($_.Value.value)`" "
        }
        Write-Host "##vso[task.setvariable variable=settingsList;isOutput=true]$settingsList"
        Write-Host "Using settings $settingsList"
  - task: AzureFunctionApp@1
    inputs:
      appSetting: $(GetSettings.settingsList)

NOTE: This may encounter issues with secret variables, in which case I'd store them in Azure Key Vault and use the key vault secrets task to read them into variables.

WaitingForGuacamole
  • 3,744
  • 1
  • 8
  • 22
  • I'm trying to run the above custom task but I get the following error "Mapping values are not allowed in this context" any idea which part of the script causes this? – Marcom May 19 '21 at 05:16