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
相关产品推荐
相关产品推荐

