首页 > 解决方案 > 使用 Azure Devops 和 Yaml 和变量组为 Azure 函数应用部署 Appsettings

问题描述

有没有办法完全部署variable group variablesAzure Function app settings使用 Yaml。

下面是 yaml 代码以及我如何部署变量:-

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.

但是如果我有很多变量,我必须提到appSettingsas中的每个变量key $(key)

那么有没有办法将我的所有变量从变量组部署到天蓝色函数应用程序设置。

非常感谢任何回应。提前致谢。

标签: azureazure-devopsyamlazure-function-app

解决方案


我不相信您可以直接在 YAML 中迭代组的变量。从我所看到的情况来看,没有任何语法可以进入该组。您可以做的是编写一个脚本,将变量从组中取出(如果您在代理上安装了 Azure CLI),然后稍后引用它:

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)

注意:这可能会遇到机密变量问题,在这种情况下,我会将它们存储在 Azure Key Vault 中并使用密钥保管库机密任务将它们读入变量。


推荐阅读