码头工人推送任务中的Azure DevOps管道参考当前标签

问题描述 投票:0回答:1

这是我的管道配置文件:

trigger:
- master

pool:
  vmImage: 'Ubuntu-16.04'

variables:
  imageName: 'pipelines-kotlin-docker'
  service-connection: 'service-connection'

steps:
# Gradle
# Build using a Gradle wrapper script
- task: Gradle@2
  inputs:
    tasks: 'build' # A list of tasks separated by spaces, such as 'build test'

- task: Docker@2
  displayName: Build an image
  inputs:
    repository: $(imageName)
    command: build
    Dockerfile: Dockerfile

- task: Docker@2
  displayName: Push image
  inputs:
    containerRegistry: |
      $(service-connection)
    repository: $(imageName)
    command: push
    tags: |
      test1

运行管道时,出现以下错误。

[错误]标签不存在:pipelines-kotlin-docker:test1

构建任务产生以下输出:Successfully tagged pipelines-kotlin-docker:396

我在推任务中用$(Build.BuildNumber)替换了test1,并收到以下错误。

[错误]无效的参考格式

如何在推入任务中引用由构建任务构建的图像标签?

docker azure-devops tags
1个回答
1
投票

Docker构建任务的默认标签为$(Build.BuildId)。检查here以获取有关构建变量的更多信息。

您应在docker push任务中将tag:test1替换为$(Build.BuildId)。您在here中检查Docker任务参数。

- task: Docker@2
  displayName: Push image
  inputs:
    containerRegistry: |
      $(service-connection)
    repository: $(imageName)
    command: push
    tags: |
      $(Build.BuildId)

或者您也可以为docker build任务指定标签:test1。并保留标签:test1用于docker push任务。

- task: Docker@2
  displayName: Build an image
  inputs:
    repository: $(imageName)
    command: build
    Dockerfile: Dockerfile
    tags: |
      test1
© www.soinside.com 2019 - 2024. All rights reserved.