Azure DevOps管道运行ARM-TTK测试时如何指定两个json文件路径
解决方案
你可以直接为Get-ChildItem的-Path参数传入多个路径组成的数组,就能同时从两个目标目录抓取JSON文件用于测试,修改后的YAML任务配置如下:
- task: PowerShell@2 displayName: 'Run deploymentTemplate tests from ARM Template Tester Toolkit' inputs: condition: always() targetType: 'inline' script: | Import-Module ./arm-ttk.psd1 Get-ChildItem -Path "$(System.DefaultWorkingDirectory)/ARM_Templates/IaaS/*.json","$(System.DefaultWorkingDirectory)/ARM_Templates/PaaS/*.json" | Test-AzTemplate -Test "Resources Should Have Location","Location Should Not Be Hardcoded", "apiversions-should-be-recent" pwsh: true workingDirectory: '$(System.DefaultWorkingDirectory)/arm-template-toolkit/arm-ttk'
调整说明
- 去掉了冗余的
cd命令,因为你已经在任务中指定了workingDirectory为ARM-TTK的目录,直接导入模块即可 Get-ChildItem的-Path参数传入了两个目标路径的数组,用英文逗号分隔,会同时匹配两个目录下的所有.json文件- 如果你的IaaS、PaaS目录下还有子目录存储ARM模板,可以在
Get-ChildItem中添加-Recurse参数,递归抓取所有层级的JSON文件,示例:Get-ChildItem -Path "$(System.DefaultWorkingDirectory)/ARM_Templates/IaaS","$(System.DefaultWorkingDirectory)/ARM_Templates/PaaS" -Filter *.json -Recurse - 注意路径大小写要和你实际仓库中的目录名称保持一致,避免路径匹配失败
内容的提问来源于stack exchange,提问作者Pallab
相关产品推荐
相关产品推荐

