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

Azure Pipeline中如何为单个Docker镜像构建添加多个标签?

Azure Pipelines Docker@2任务添加多个镜像标签的实现方法

完全可以给一次Docker构建添加多个标签,你提供的配置代码已经是正确的实现方式。

在Docker@2任务中,tags字段支持通过多行文本的形式指定多个标签,每个标签单独占一行即可。比如你配置里的:

task: Docker@2
inputs:
  containerRegistry: 'my-registry'
  repository: '$(System.TeamProject)/$(Build.Repository.Name)'
  command: 'buildAndPush'
  Dockerfile: 'Dockerfile'
  tags: |
    $(Build.SourceVersion)
    $(Build.SourceBranchName)

这段配置会为构建出的镜像同时打上两个标签:一个是代码提交的哈希值($(Build.SourceVersion)),另一个是当前构建的分支名称($(Build.SourceBranchName))。

如果需要添加更多标签,只需要在tags的多行文本里继续追加新行即可,比如:

tags: |
  $(Build.SourceVersion)
  $(Build.SourceBranchName)
  latest

这样就能给镜像额外加上latest标签。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 22:42:02