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

如何修复Semaphore平台YAML报错:Block mapping value not allowed here

错误根因

触发解析错误的原因有两个:

  1. 缩进错误:YAML依赖缩进来识别层级关系,你当前的配置中所有子属性(比如task下的prologue、jobs,auto_promote_on下的result、branch等)都没有正确缩进,和父属性平级,导致解析器无法识别结构。
  2. 字段名错误:Semaphore 2.0的auto_promote_on规则中,匹配多个分支/标签的字段为复数形式branches,你用了单数branch,该字段不支持直接嵌套列表,进一步触发解析异常。
修复方法

修改.semaphore/semaphore.yml的配置即可:

  1. 统一所有层级使用2个空格缩进,保证子属性比父属性多2个空格
  2. 将auto_promote_on下的branch字段改为branches,可以保留原有正则匹配规则,也可以简化标签匹配(Semaphore会自动识别标签上下文,无需额外加refs/tags/前缀)

修复后的完整配置参考:

# .semaphore/semaphore.yml
version: v1.0
name: Build
agent:
  machine:
    type: e1-standard-2
    os_image: ubuntu1804

blocks:
  - name: "Test"
    task:
      prologue:
        commands:
        # set go version
        - sem-version go 1.11
        - "export GOPATH=~/go"
        - "export PATH=/home/semaphore/go/bin:$PATH"
        - checkout

      jobs:
        - name: "Lint"
          commands:
          - go get ./...
          - go test ./...

# On Semaphore 2.0 deployment and delivery is managed with promotions,
# which may be automatic or manual and optionally depend on conditions.
promotions:
  - name: Release
    pipeline_file: goreleaser.yml
    auto_promote_on:
      - result: passed
        branches:
          - "^v*"

如果需要严格匹配带前缀的标签引用,也可以保留"^refs/tags/v*"规则,只要将字段名改为branches即可正常解析。提交前可以本地用yamllint等工具先校验YAML缩进和语法,避免低级错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 21:45:03