title: Build and push a docker image with build arguments from DevOps to ACR
body: <p>I'm building a docker image in an Azure DevOps pipeline, then I want to push it to the Azure Container registry. The registry is already created and I've configured DevOps to use it, also the <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/containers/acr-template?view=azure-devops#how-we-build-your-pipeline" rel="noreferrer"><code>buildAndPush</code> Docker task</a> works.</p>
  <p>However, since the Docker build can be parametrized, I want to pass arguments to it and <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/docker?view=azure-devops#task-inputs" rel="noreferrer">I can't do it</a> using the <code>buildAndPush</code> Docker task. So I've decided to do it in two steps, one for building and the other one for pushing. This way:</p>
  <pre class="lang-yml prettyprint-override"><code># Docker
  # Build and push an image to Azure Container Registry
  # https://docs.microsoft.com/azure/devops/pipelines/languages/docker
  trigger: none
  
  resources:
  - repo: self
  
  variables:
    # Container registry service connection established during pipeline creation
    dockerRegistryServiceConnection: 'aaaa-aaaa-aaaa-aaaa-aaaaa'
    imageRepository: 'ubuntu-qt'
    containerRegistry: 'myregistry.azurecr.io'
    dockerfilePath: '$(Build.SourcesDirectory)/docker-qt-build/Dockerfile'
    
    # Agent VM image name
    vmImageName: 'ubuntu-latest'
  
  stages:
  - stage: BuildPush
    displayName: Build and push
    jobs:  
    - job: Build
      displayName: Build
      pool:
        vmImage: $(vmImageName)
      steps:
      - task: Docker@2
        displayName: Build ubuntu with qt 5.12.4 installed
        inputs:
          command: build
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          tags: 5.12.4
          arguments: '--build-arg ubuntu_version=18.04 --build-arg qt_version_major=5.12 --build-arg qt_version_full=5.12.4'
      - task: Docker@2
        displayName: Push ubuntu with qt 5.12.4 installed
        inputs:
          command: push
          repository: $(imageRepository)
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: myregistry.azurecr.io/ubuntu-qt:5.12.4
  </code></pre>
  <p>Even if the build task works well, it doesn't seem to be able to find the image for pushing to the registry:</p>
  <pre><code>Starting: Push ubuntu with qt 5.12.4 installed
  ==============================================================================
  Task         : Docker
  Description  : Build or push Docker images, login or logout, or run a Docker command
  Version      : 2.170.2
  Author       : Microsoft Corporation
  Help         : https://aka.ms/azpipes-docker-tsg
  ==============================================================================
  /usr/bin/docker images
  /usr/bin/docker push ***/ubuntu-qt:***/ubuntu-qt:5.12.4
  invalid reference format
  ##[error]invalid reference format
  ##[error]The process '/usr/bin/docker' failed with exit code 1
  REPOSITORY                                           TAG                 IMAGE ID            CREATED             SIZE
  ubuntu-qt                                            5.12.4              e5aeb1027823        2 seconds ago       6.64GB
  ubuntu                                               18.04               2eb2d388e1a2        12 days ago         64.2MB
  node                                                 10                  5010eb9431a5        2 weeks ago         911MB
  node                                                 12                  dfbb88cfffc8        2 weeks ago         918MB
  buildpack-deps                                       stretch             42d486287f16        2 weeks ago         835MB
  debian                                               9                   5df937d2ac6c        2 weeks ago         101MB
  debian                                               8                   72f79d3cb645        2 weeks ago         129MB
  node                                                 10-alpine           8e473595b853        2 weeks ago         83.5MB
  node                                                 12-alpine           057fa4cc38c2        5 weeks ago         89.3MB
  jekyll/builder                                       latest              12489946feab        7 weeks ago         674MB
  alpine                                               3.9                 78a2ce922f86        3 months ago        5.55MB
  alpine                                               3.10                be4e4bea2c2e        3 months ago        5.58MB
  alpine                                               3.8                 c8bccc0af957        6 months ago        4.41MB
  ubuntu                                               14.04               6e4f1fe62ff1        7 months ago        197MB
  alpine                                               3.7                 6d1ef012b567        17 months ago       4.21MB
  mcr.microsoft.com/azure-pipelines/node8-typescript   latest              9a948d360778        22 months ago       595MB
  
      Finishing: Push ubuntu with qt 5.12.4 installed
  </code></pre>