我正在尝试使用Azure DevOps管道构建映像并将其推送到Azure容器注册表,但收到以下错误:
"base name (${BUILD_IMAGE}) should not be blank"
在尝试构建映像时。我检查了我的管道配置文件,但找不到定义的变量BUILD_IMAGE
。从错误消息来看,该变量似乎正在Dockerfile的FROM
语句中使用,但我不知道应该在哪里定义它。我检查了管道配置文件、触发管道的脚本和命令行,但我找不到变量的定义位置。我还检查了带有标签$(Build.BuildId)
或510914
的图像aquariumcms
是否存在于注册表rgaquariumtestimagewesteu.azurecr.io
中,以及是否可以从管道访问它,但我找不到任何问题。我的管道正在使用Docker@2
和DockerCompose@0
任务,容器注册表是rgaquariumtestimagewesteu.azurecr.io
,如何添加变量BUILD_IMAGE
,使其不再为空,管道可以构建映像并将其推送到容器注册表?
The pipeline
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- Initial-K8-Setup
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '7739b21f-2572-4f36-ab8b-df15ab821756'
imageRepository: 'aquariumcms'
containerRegistry: 'rgAquariumTestImageWestEU.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
tag: '$(Build.BuildId)'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: 'HAWeb2-CFS-NonProd'
azureContainerRegistry: '{"loginServer":"rgAquariumTestImageWestEU.azurecr.io", "id" : "/subscriptions/5e2acfcb-7aeb-443d-9ea4-bc7553a51276/resourceGroups/rg-haweb-cfs-nonprod-web2-001/providers/Microsoft.ContainerRegistry/registries/rgAquariumTestImageWestEU"}'
dockerComposeFile: '**/docker-compose.yml'
additionalDockerComposeFiles: 'docker-compose.override.yml'
dockerComposeFileArgs: 'REGISTRY=rgAquariumTestImageWestEU.azurecr.io/'
action: 'Build services'
additionalImageTags: '$(Build.BuildNumber)-$(Build.SourceBranchName)'
includeLatestTag: true
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: 'HAWeb2-CFS-NonProd'
azureContainerRegistry: '{"loginServer":"rgAquariumTestImageWestEU.azurecr.io", "id" : "/subscriptions/5e2acfcb-7aeb-443d-9ea4-bc7553a51276/resourceGroups rg-haweb-cfs-nonprod-web2-001/providers/Microsoft.ContainerRegistry/registries/rgAquariumTestImageWestEU"}'
dockerComposeFile: '**/docker-compose.yml'
additionalDockerComposeFiles: 'docker-compose.override.yml'
dockerComposeFileArgs: 'REGISTRY=rgAquariumTestImageWestEU.azurecr.io/'
action: 'Push services'
additionalImageTags: '$(Build.BuildNumber)-$(Build.SourceBranchName)'
includeLatestTag: true
预期管道将生成映像并将其推送到管道配置文件中指定的Azure容器注册表。但是,管道在尝试生成映像时失败,并显示错误消息“基本名称(${BUILD_IMAGE})不应为空”,这表明BUILD_IMAGE变量为空或未定义。
尽管我收到了以下错误日志
Starting: Build and push an image to container registry
==============================================================================
Task : Docker
Description : Build or push Docker images, login or logout, start or stop containers, or run a Docker command
Version : 2.214.0
Author : Microsoft Corporation
Help : https://aka.ms/azpipes-docker-tsg
==============================================================================
/usr/bin/docker build -f /home/vsts/work/1/s/Dockerfile --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/dgsit/ --label com.azure.dev.image.system.teamproject=Sitecore --label com.azure.dev.image.build.repository.name=aquarium-cms --label com.azure.dev.image.build.sourceversion=dad7e8024ac8bba9b7b58bce934cdc96729da5cb --label com.azure.dev.image.build.repository.uri=https://dgsit@dev.azure.com/dgsit/Sitecore/_git/aquarium-cms --label com.azure.dev.image.build.sourcebranchname=Initial-K8-Setup --label com.azure.dev.image.build.definitionname=aquarium-cms (1) --label com.azure.dev.image.build.buildnumber=20230118.7 --label com.azure.dev.image.build.builduri=vstfs:///Build/Build/511111 -t ***/aquariumcms:511111 /home/vsts/work/1/s
Sending build context to Docker daemon 15.5MB
Step 1/29 : ARG BASE_IMAGE
Step 2/29 : ARG BUILD_IMAGE
Step 3/29 : FROM ${BUILD_IMAGE} AS prep
base name (${BUILD_IMAGE}) should not be blank
##[error]base name (${BUILD_IMAGE}) should not be blank
##[error]The process '/usr/bin/docker' failed with exit code 1
Finishing: Build and push an image to container registry
1条答案
按热度按时间igetnqfo1#
这对我来说很有效,它覆盖了repo中的“最新”版本,并基于BuildID创建了一个新的独立版本。
在标签下方添加构建版本。
下面是我的示例azure-pipeline.yml
有关类似问题的更多信息,请参见此github问题[8378](Docker push no longer pushes *:latest tag with includeLatestTag: true · Issue #8378 · microsoft/azure-pipelines-tasks (github.com))