能否在YAML中为AppSettings指定JSON模板文件?
关于AzureAppServiceSettings任务使用JSON模板配置AppSettings的问题
不行,AzureAppServiceSettings@1任务的appSettings参数不支持直接指定JSON文件路径,它仅接受内联的JSON数组格式内容,或者通过变量引用的内联JSON字符串。
不过可以通过以下步骤实现类似效果:
读取JSON模板文件内容到变量
添加PowerShell或Bash任务,将模板文件的内容读取并存储到管道变量中:# PowerShell示例 $appSettingsContent = Get-Content -Path "$(System.DefaultWorkingDirectory)/templates/appSettings.json" -Raw Write-Host "##vso[task.setvariable variable=AppSettingsJson]$appSettingsContent"在AzureAppServiceSettings任务中引用变量
把刚才的变量传入appSettings参数:- task: AzureAppServiceSettings@1 displayName: Azure App Service Settings inputs: azureSubscription: ssubscription appName: appname appSettings: $(AppSettingsJson)可选:替换模板中的变量占位符
如果你的JSON模板里包含$(VAR_ONE)这类管道变量占位符,需要先使用FileTransform@1任务替换这些占位符,再读取文件内容:- task: FileTransform@1 displayName: Replace variables in AppSettings template inputs: folderPath: $(System.DefaultWorkingDirectory)/templates fileType: json targetFiles: appSettings.json
内容的提问来源于stack exchange,提问作者James Blackburn
相关产品推荐
相关产品推荐

