Azure Devops – release pipeline with docker and Azure Container Registry (ACR) – problem with tag

I have a very weird (and I suppose easy to fix) problem 🙂 I am trying to have a working CI/CD pipeline in Azure. For this purpose, I have a repository in Azure devops and build and release pipeline created. I am publishing docker images to Azure Container Registry and during release, I am pulling this image (or at least – I am trying because it doesn’t work) and I am trying to publish it on Webapp for containers. The “app” in my case it is SingalR hub on .NET Core 3.1 (but I don’t suppose it makes a difference in the problem I am having)

If somebody wants to know in details how did i configure it – here is the tutorial i did use:

https://wikiazure.com/devops/azure-devops-automate-your-release-pipeline-to-provision-a-docker-container-to-azure-web-app-for-containers/

There were some doubts/differences in the tutorial (for example – why initially in the tutorial web app is being configured on Docker hub, when in fact it is using ACR. And why to connect to ACR the tutorial uses Azure Resource Manager connection (And not dedicated Docker container –> ACR connetion) And why later on in build pipeline there is some weird id set for dockerRegistryServiceConnection (i am giving in this place name of my ACR docker service connection)

But the whole build pipeline is working. It is publishing image to ACR. Everything is fine till this step.

The problem starts when I want to publish Azure WebApp with this image. The problem is with … TAGS 🙂 They are mismatching. I have automatic CI/CD – so when i push some change to the repo i see that release pipeline is working. It is creating the image in the ACR. Then i see, that release pipeline is running. Everything is “correct” – meaning no error are seen and the release is green.

But when i go to App service and Container settings i see from logs:

2020-04-21 18:02:28.321 INFO  - Pulling image: myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a
2020-04-21 18:02:28.761 ERROR - DockerApiException: Docker API responded with status code=NotFound, response={"message":"manifest for myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a not found: manifest unknown: manifest unknown"}

2020-04-21 18:02:28.761 ERROR - Pulling docker image myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a failed:
2020-04-21 18:02:28.762 INFO  - Pulling image from Docker hub: myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a
2020-04-21 18:02:28.867 ERROR - DockerApiException: Docker API responded with status code=InternalServerError, response={"message":"Get https://myAcrName.azurecr.io/v2/mobile/signalr/manifests/c7aead0c46b66afc4131935efc7e6a51280dfb1a: unauthorized: authentication required"}

2020-04-21 18:02:28.870 ERROR - Image pull failed: Verify docker image configuration and credentials (if using private repository)

Very sophisticated error but the root cause is, that he is trying to get the image with non-existing tag, which is GIT COMMIT tag. And it suppose to get image by $(Build.BuildId) (this was my first attempt) or by $(Build.BuilNumber) (this was my second attempt)

Here is how this pipeline step (Deploy Azure App Service) looks like:

- task: [email protected]
  displayName: 'Deploy Azure App Service'
  inputs:
    azureSubscription: mySubcsriptionARM
    appType: webAppContainer
    WebAppName: myProductsignalr
    DockerNamespace: myAcrName.azurecr.io
    DockerRepository: mobile/signalr
    DockerImageTag: '$(Build.BuildNumber)'

When i go to Release pipeline logs as a “Deploy Azure App Service” log i see that

2020-04-21T18:41:01.6012767Z ##[section]Starting: Deploy Azure App Service
2020-04-21T18:41:01.6367124Z ==============================================================================
2020-04-21T18:41:01.6367787Z Task         : Azure App Service deploy
2020-04-21T18:41:01.6368381Z Description  : Deploy to Azure App Service a web, mobile, or API app using Docker, Java, .NET, .NET Core, Node.js, PHP, Python, or Ruby
2020-04-21T18:41:01.6368765Z Version      : 4.163.5
2020-04-21T18:41:01.6369158Z Author       : Microsoft Corporation
2020-04-21T18:41:01.6369603Z Help         : https://aka.ms/azureappservicetroubleshooting
2020-04-21T18:41:01.6369976Z ==============================================================================
2020-04-21T18:41:03.8970184Z Got service connection details for Azure App Service:'myProductsignalr'
2020-04-21T18:41:04.5534864Z Trying to update App Service Configuration settings. Data: {"appCommandLine":null,"linuxFxVersion":"DOCKER|myAcrName.azurecr.io/mobile/signalr:1f283100"}
2020-04-21T18:41:05.5465725Z Updated App Service Configuration settings.
2020-04-21T18:41:05.5495890Z Trying to update App Service Application settings. Data: {"DOCKER_CUSTOM_IMAGE_NAME":"myAcrName.azurecr.io/mobile/signalr:1f283100"}
2020-04-21T18:41:06.2703349Z Updated App Service Application settings and Kudu Application settings.
2020-04-21T18:41:32.4715682Z Updated App Service Application settings and Kudu Application settings.
2020-04-21T18:41:33.4179962Z Successfully updated deployment History at https://myProductsignalr.scm.azurewebsites.net/api/deployments/111587494492765
2020-04-21T18:41:33.5945654Z App Service Application URL: http://myProductsignalr.azurewebsites.net
2020-04-21T18:41:33.6180118Z ##[section]Finishing: Deploy Azure App Service

enter image description here

What amazes me, that it is showing, that everything was ok – when it was far from “ok” 🙂

When i go to container settings after:
a) new code is published
b) build pipeline fires
c) release pipeline fires

i see it like this:

enter image description here

The tag is empty. If i would pick some tag manually:

enter image description here

And would choose: “SAVE” everything works correctly (SingalR is up and running correctly)

Clearly, I am missing something :/ Help me to see what;)

The root cause for me is that this fragment:
DockerImageTag: '$(Build.BuildNumber)'
should insert build number (as stated) and the info from container settings should be:
Pulling image: myAcrName.azurecr.io/mobile/signalr:20200421.09 (for BuildNumber 20200421.09) and it is inserting GIT COMMIT there as a tag and ends up with: Pulling image: myAcrName.azurecr.io/mobile/signalr:c7aead0c46b66afc4131935efc7e6a51280dfb1a Why o why?:)

Source: StackOverflow