skip to Main Content

I want my Azure DevOps pipeline to deploy all the function app configs without manually entering them in the devops pipeline how to do that ?

We’ve C# code which is getting deployed on Azure function apps. But we’re adding the configs of fucntion apps manually in azure devops pipeline.

As of now we’re entering the configs in Azure function deploy task in pipeline, but I want it as it needs to come from source code directly without enteritng them in pipeline.

We need direction to understand how we can automate the config vaules by using ADO pipelines. Is this possible ?

2

Answers


  1. You can add a task to run an Azure CLI script to edit app settings in bulk:

    az webapp config appsettings set 
      --resource-group <group-name> 
      --name <app-name> 
      --settings "@settings.json"
    

    The file format needed for settings.json is a JSON array of settings where the slot setting field is optional

    [
      {
        "name": "key1",
        "slotSetting": false,
        "value": "value1"
      },
      {
        "name": "key2",
        "value": "value2"
      }
    ]
    

    For convenience, you can save existing settings into a JSON file with az webapp config appsettings list. The following example can be run in Bash:

    # Save the settings
    az webapp config appsettings list --name <app-name> --resource-group <group-name> > settings.json
    
    # Edit the JSON file
    ...
    
    # Update the app with the JSON file
    az webapp config appsettings set --resource-group <group-name> --name <app-name> --settings @settings.json
    
    Login or Signup to reply.
  2. The appsettings.json file can not be directly used in the Azure CLI: az webapp config appsettings set.

    is there any other way which will directly pull all the configs in appsettings.json file and deploy directly all those configs on function app ?

    To meet your requirement, you can use script to loop the app settings value in the appsettings.json file. Then you can add them to an array and use it to the Azure CLI commnad.

    Here is an example:

    steps:
    
    
    - task: AzureCLI@2
      inputs:
        azureSubscription: 'xxx'
        scriptType: 'ps'
        scriptLocation: 'inlineScript'
        inlineScript: |
          $json = Get-Content '$(build.sourcesdirectory)/AzureFunctionAppSettings/Startup/appsettings.json' | Out-String | ConvertFrom-Json
          
          $appsettingnames =  $json.values | Get-Member | Where {$_.MemberType -like 'NoteProperty'} | Select-Object  -Property name
          
          $appsettingslist = @()
    
          ForEach ($appsettingname in $appsettingnames.name)
          {
            $appsettingvalue =  $json.values.$appsettingname
    
            $singleappsetting = "`"$appsettingname=$appsettingvalue`""
    
            $appsettingslist = $appsettingslist + $singleappsetting
          }
    
          echo $appsettingslist
    
          
          az webapp config appsettings set --resource-group resourcegroupname --name functionappname --settings $appsettingslist
      
    

    Result sample:

    enter image description here

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