You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps Pipelines YAML模板报错:不允许映射

解决Azure Pipelines steps.yml模板中“不允许映射”错误

问题重现

配置的模板文件如下:

azure-pipelines.yml:

jobs:   
  - job: VS2019 
    pool:
       name: VS2019
    steps:
    - template: steps.yml   

steps.yml:

steps:
- task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
        projects: '**/*.sln'
        arguments: '--no-restore --configuration $(BuildConfiguration)'

运行时在steps.yml的第3行第16列(displayName行)提示“不允许映射”错误,检查缩进、更换任务后问题依旧。

解决方案

问题出在YAML的缩进不规范,task节点的子属性(displayName、inputs)必须与task的起始层级保持一致的缩进,不能额外多缩进。修正后的steps.yml如下:

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: '**/*.sln'
    arguments: '--no-restore --configuration $(BuildConfiguration)'

YAML对缩进的要求非常严格,所有同级节点的缩进必须统一(建议使用2个空格),子节点的缩进要比父节点多一级。原配置中displayName和inputs的缩进比task节点多了过多空格,导致YAML解析器无法识别正确的层级结构,从而抛出“不允许映射”的错误。

内容的提问来源于stack exchange,提问作者Rodri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 09:43:10