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

Azure发布管道模板解析错误求助:未找到预期键

问题分析与解决

这个YAML解析错误的核心原因是YAML缩进格式不规范,导致解析器无法正确识别任务块的层级结构。具体问题及修正如下:

错误点1:checkout任务的子属性未正确缩进

你提供的checkout任务代码中,submodules和persistCredentials是checkout任务的子属性,必须缩进(通常2或4个空格),否则YAML解析器会将它们视为独立的顶级键,引发"未找到预期键"的错误。

错误点2:bash任务的命令行未正确缩进

bash任务的多行命令(|开头的块),内部的echo语句需要缩进,确保属于bash任务的命令块。

修正后的完整代码片段

- bash: |
    echo "##vso[task.setvariable variable=mySecretPAT;issecret=true]${{ parameters.pat }}"

# pat must be specified
- script: exit 1
  displayName: Fail if pat not specified
  condition: eq('${{ parameters.pat }}', 'NA')

# Setup
- script: |
    git config --global user.email "$(Build.RequestedForEmail)"
    git config --global user.name "$(Build.RequestedFor)"
  displayName: Setup for build

- checkout: self
  submodules: true
  persistCredentials: true

关键修正说明

  1. 给checkout任务的submodules和persistCredentials添加缩进,使其明确属于checkout任务块。
  2. 确保bash和script任务的多行命令内部语句都有正确缩进,符合YAML块映射的格式要求。
  3. 所有任务以-开头,任务的属性(如displayName、condition、子属性)都需缩进在任务行下方,保持层级清晰。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 13:07:06