docker - Azure DevOps Pipeline reference current tag in docker push task
问题描述
Here is my pipeline configuration file:
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
When running the pipeline I get the following error.
[error]tag does not exist: pipelines-kotlin-docker:test1
The build task yields the following output:
Successfully tagged pipelines-kotlin-docker:396
I replaced test1 with $(Build.BuildNumber) in the push task and got the following error.
[error]invalid reference format
How can I reference the tag of the image which has been built by the build task in the push task?
解决方案
The Default tag for Docker build task is $(Build.BuildId)
. Check here for more information about Build variables.
You should replace tag:test1 to $(Build.BuildId) in docker push task. You check here for Docker task parameters.
- task: Docker@2
displayName: Push image
inputs:
containerRegistry: |
$(service-connection)
repository: $(imageName)
command: push
tags: |
$(Build.BuildId)
Or you can also specify the tag: test1 for docker build task. and keep the tag: test1 for docker push task.
- task: Docker@2
displayName: Build an image
inputs:
repository: $(imageName)
command: build
Dockerfile: Dockerfile
tags: |
test1
推荐阅读
- php - 无法在 php 中设置动态类名
- java - 为两个不同的移动实例化一个撤销方法
- python - Pycharm:无法基于python 3.9.01+制作venv
- wpf - Powershell GUI 冻结,即使使用运行空间
- javascript - Javascript innerText - 回车 - 正则表达式不起作用
- python - Python 和 SQLite 需要帮助 --> TypeError: 'NoneType' object is not subscriptable
- python-3.x - 使用另一个列表创建一个列表
- firebase - 使用从前端应用程序获取的 firebase 令牌处理 Spring Boot REST API 中的身份验证
- python - 为数据集绘制图形以在 Python 上开发 SVM
- c++ - 有没有办法在不使用系统时钟的情况下在 C++ 中获取时间和日期?