如何修复Semaphore平台YAML报错:Block mapping value not allowed here
错误根因
触发解析错误的原因有两个:
- 缩进错误:YAML依赖缩进来识别层级关系,你当前的配置中所有子属性(比如
task下的prologue、jobs,auto_promote_on下的result、branch等)都没有正确缩进,和父属性平级,导致解析器无法识别结构。 - 字段名错误:Semaphore 2.0的
auto_promote_on规则中,匹配多个分支/标签的字段为复数形式branches,你用了单数branch,该字段不支持直接嵌套列表,进一步触发解析异常。
修复方法
修改.semaphore/semaphore.yml的配置即可:
- 统一所有层级使用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
相关产品推荐
相关产品推荐

