skip to Main Content

As part of my pipeline, I am creating a new Azure Registry Container and then building and pushing a container to it.

Normally to push to a registry I can just run this task.

  - task: Docker@2
    displayName: Build and push an image to container registry
    inputs:
      containerRegistry: 'todeleteaksdemoacr'
      repository: 'webappdocker'
      command: 'buildAndPush'
      Dockerfile: 'WebAppDocker/Dockerfile'
      tags: 'prod'

This only works if I have a Service Connection set up.

enter image description here

However, in my case, the registry container is being created in a previous step within my pipeline. So I don’t have a service connection available for it.

When I run the pipeline, I’m getting the error "There was a resource authorization issue: "The pipeline is not valid. Job Job1: Step Docker input containerRegistry references service connection todeleteaksdemoacr which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz."

enter image description here

The service connection cannot be found obviously because the container registry doesn’t exist. How can I get around this? Is there another way to push to the container registry?

2

Answers


  1. Chosen as BEST ANSWER

    I ended up doing this instead and it worked

      - task: AzureCLI@2
        displayName: 'Login to ACR'
        inputs:
          azureSubscription: '<sub ID>'
          scriptType: 'bash'
          scriptLocation: 'inlineScript'
          inlineScript: |
            az acr login --name ${{parameters.acr_name}}
            docker build -t <conatinername>:prod .
            docker push ${{parameters.acr_name}}.azurecr.io/<containername>:prod
    

  2. I recommend you use the Docker@1 task to build and push the image like as below.

    steps:
    - task: Docker@1
      displayName: 'Build image'
      inputs:
        containerregistrytype: 'Azure Container Registry'
        azureSubscriptionEndpoint: '$(ArmConnection)'
        azureContainerRegistry: '$(AcrName)'
        command: 'build'
        dockerFile: path/to/Dockerfile
        imageName: '$(image_name):$(image_tag)'
    
    - task: Docker@1
      displayName: 'Push image'
      inputs:
        containerregistrytype: 'Azure Container Registry'
        azureSubscriptionEndpoint: '$(ArmConnection)'
        azureContainerRegistry: '$(AcrName)'
        command: 'push'
        imageName: '$(image_name):$(image_tag)'
    

    You can use the pipeline variables/parameters to dynamically specify the values for the following inputs:

    • $(ArmConnection) can be either an ARM service connection or an Azure Subscription that contains the ACR.

    • $(AcrName) is the name of the ACR.

    • $(image_name) is the name of the Docker image will be built. It also is name of the Container repository.

    • $(image_tag) is the tag of the image.


    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search