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

Azure DevOps Docker@2任务多标签配置失败求助

Azure DevOps Docker@2 多标签配置解决方法

正确配置方式

1. 多行字符串写法(推荐)

使用YAML的多行字符串标记|来定义标签,每个标签单独一行,确保缩进正确:

- task: Docker@2
  displayName: Build and push Docker image
  inputs:
    command: 'buildAndPush'
    containerRegistry: '你的容器注册表服务连接名'
    repository: '你的镜像仓库名'
    dockerfile: '**/Dockerfile'
    tags: |
      latest
      $(Build.BuildId)
      v1.0.0

|会保留换行符,Docker@2任务会自动将每行内容识别为独立标签。

2. 单行逗号分隔写法

如果偏好单行配置,可直接用逗号分隔多个标签:

- task: Docker@2
  displayName: Build and push Docker image
  inputs:
    command: 'buildAndPush'
    containerRegistry: '你的容器注册表服务连接名'
    repository: '你的镜像仓库名'
    dockerfile: '**/Dockerfile'
    tags: 'latest,$(Build.BuildId),v1.0.0'

错误原因说明

  • 列表格式报错:Docker@2的tags字段仅接受字符串类型,不能直接用YAML序列(- 标签)的格式定义,否则会触发"A sequence was not expected"错误。
  • 直接换行报错:未使用|标记多行字符串时,YAML会将换行后的内容解析为单个带换行的字符串,Docker会把整个内容当作一个非法标签,导致镜像引用格式错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 21:12:04