Azure DevOps与VS Code中YAML配置报错:隐式键格式问题求助
Azure DevOps Pipeline YAML配置报错修复
错误场景
用于构建Windows Service并下载.exe文件的Azure DevOps Pipeline YAML配置,在Azure DevOps和VS Code的YAML扩展中均触发语法错误,错误提示:
Implicit keys need to be on a single line, Implicit map keys need to be followed by map values
错误的YAML代码
trigger: - develop pool: vmImage: windows-2019 - task: MSBuild@1 inputs: solution: '**/*.sln' - task: DownloadBuildArtifacts@1 inputs: buildType: 'current' downloadType: 'single' itemPattern: '**/*.exe' downloadPath: '$(System.ArtifactsDirectory)'
错误原因
YAML语法不符合Azure DevOps Pipeline的结构要求:任务(task)必须嵌套在jobs -> steps的层级下,原配置直接在根节点下定义task列表,导致YAML解析器无法识别正确的映射结构,触发语法错误。
修复后的YAML代码
trigger: - develop jobs: - job: BuildAndDownload pool: vmImage: windows-2019 steps: - task: MSBuild@1 inputs: solution: '**/*.sln' - task: DownloadBuildArtifacts@1 inputs: buildType: 'current' downloadType: 'single' itemPattern: '**/*.exe' downloadPath: '$(System.ArtifactsDirectory)'
修复说明
- 添加
jobs节点,定义一个名为BuildAndDownload的作业 - 将原
pool配置移至该作业节点下 - 添加
steps节点,把所有task放入这个数组中,确保YAML结构符合Azure DevOps Pipeline的语法规范
内容的提问来源于stack exchange,提问作者Marcie
相关产品推荐
相关产品推荐

