Home > Enterprise >  Build and push image to ACR - ##[error]base name (${BUILD_IMAGE}) should not be blank
Build and push image to ACR - ##[error]base name (${BUILD_IMAGE}) should not be blank

Time:01-20

I am trying to build and push an image to Azure Container Registry using Azure DevOps pipeline, but I am getting the following error:

"base name (${BUILD_IMAGE}) should not be blank" 

when trying to build the image. I have checked my pipeline configuration file and I couldn't find the variable BUILD_IMAGE defined. From the error message, it seems that the variable is being used in the FROM statement in the Dockerfile but I don't know where it's supposed to be defined. I have checked the pipeline configuration file, the script that triggers the pipeline, and the command-line but I couldn't find where the variable is defined. I have also checked if the image aquariumcms with tag $(Build.BuildId) or 510914 exists in the registry rgaquariumtestimagewesteu.azurecr.io and if it's accessible from the pipeline but I couldn't find any issues. My pipeline is using the Docker@2 and DockerCompose@0 tasks, and the container registry is rgaquariumtestimagewesteu.azurecr.io. How can I add the variable BUILD_IMAGE so it's no longer blank and the pipeline can build and push the image to the container registry?

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

The expectation was that the pipeline would build and push the image to the Azure Container Registry specified in the pipeline configuration file. However, the pipeline is failing with the error message "base name (${BUILD_IMAGE}) should not be blank" when trying to build the image, indicating that the BUILD_IMAGE variable is empty or not defined.

Although I receive the following error log

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://[email protected]/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

enter image description here

CodePudding user response:

this is working for me, it overwrites the "latest" version in the repo as well as creates a new independent version based on the BuildID.

Under build added below tags.

  tags: |
      latest
      $(Build.BuildId)

Here is my sample azure-pipeline.yml

# Docker
  
trigger:
- main

resources:
- repo: self

variables:
  dockerRegistryServiceConnection: '...'
  imageRepository: 'mycontainer'
  containerRegistry: 'azuk.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/dockerfile'
  tag: '$(Build.BuildId)'
  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 $(container.registry)'
          inputs:
            containerRegistry: '$(container.registry)'
            repository: '$(container.repository)'
            Dockerfile: '**/Dockerfile'
            command: 'buildAndPush'
            tags: |
              latest
              $(Build.BuildId)

refer to this github issue [8378](Docker push no longer pushes *:latest tag with includeLatestTag: true · Issue #8378 · microsoft/azure-pipelines-tasks (github.com)) for more information regardign similar issue

  • Related