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.
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."
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
I ended up doing this instead and it worked
I recommend you use the Docker@1 task to build and push the image like as below.
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.