azureazure-devopsazure-pipelinesazure-devops-self-hosted-agent

Azure DevOps pipeline - Docker failed to push image to Azure Container Registry


I have created a "Docker - Build and push an image to Azure Container Registry" pipeline. I have selected the Azure subscription and the docker registry. After that, a docker registry service connection is made during the pipeline creation. Next, I modified the azure-pipelines.yml file to use a self-hosted agent pool and disabled the trigger.

trigger:
- none

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '***'
  imageRepository: 'devops'
  containerRegistry: '***.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:
  - job: Build
    displayName: Build
    pool: my-personal-computer
    steps:
    - task: Docker@2
      displayName: Build and push an image to container registry
      inputs:
        command: buildAndPush
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        containerRegistry: $(dockerRegistryServiceConnection)
        tags: $(tag)

However, running the pipeline resulted in an error. The Build and push an image to container registry task failed after pushing the docker image to Azure Container Registry. Here is the log message:

The push refers to repository [***/devops]
63b2598121d3: Preparing
8851d7ecbda2: Preparing
e76d0c14c9a4: Preparing
e016983c630a: Preparing
5f859dff6480: Preparing
bbf9d20826f5: Preparing
d8fab46d7ad4: Preparing
2e4e72005dce: Preparing
24839d45ca45: Preparing
bbf9d20826f5: Waiting
d8fab46d7ad4: Waiting
2e4e72005dce: Waiting
24839d45ca45: Waiting
denied: retrieving permissions failed
##[error]The process 'C:\Program Files\Docker\Docker\resources\bin\docker.exe' failed with exit code 1

It said that retrieving the permission failed. So I executed both the Docker Desktop and the <my-selfhosted-agent-path>\run.cmd as administrator. Unfortunately, it did not solve the issue. Therefore I looked inside the <my-selfhosted-agent-path\_diag folder and checked out a Worker log:

[2023-07-11 09:01:16Z INFO BuildJobExtension] Total accessible running process: 334.
[2023-07-11 09:01:16Z INFO BuildJobExtension] Inspecting process environment variables. PID: 21688 (SearchProtocolHost)
[2023-07-11 09:01:16Z WARN BuildJobExtension] Ignore exception during read process environment variables: Access is denied.
[2023-07-11 09:01:16Z INFO BuildJobExtension] Inspecting process environment variables. PID: 4384 (SearchFilterHost)
[2023-07-11 09:01:16Z WARN BuildJobExtension] Ignore exception during read process environment variables: Access is denied.
[2023-07-11 09:01:16Z INFO BuildJobExtension] Inspecting process environment variables. PID: 20736 (docker)
[2023-07-11 09:01:16Z INFO BuildJobExtension] Inspecting process environment variables. PID: 22712 (conhost)
[2023-07-11 09:01:16Z INFO BuildJobExtension] Inspecting process environment variables. PID: 1664 (com.docker.cli)
[2023-07-11 09:01:16Z INFO BuildJobExtension] Inspecting process environment variables. PID: 4476 (docker-scout)
[2023-07-11 09:01:16Z INFO JobRunner] Job result after all job steps finish: Failed

It looks like there are some access problems during the job. I do not know why docker failed to push the image when yesterday everything worked just fine.


Solution

  • I have managed to successfully run the pipeline by recreating a completely new pipeline. I deleted the automatically created pipeline under the Pipelines page, the azure-pipeline.yml file from the repository, and the service connection under the Project Settings > Pipelines > Service Connections setting.

    Next, I generated the "Docker - Build and push an image to Azure Container Registry" Azure pipeline. I selected the subscription and the Azure Container Registry (ACR). I modified the azure-pipeline.yml file to use my self-hosted agent and disabled the trigger.

    trigger: none
    
    resources:
    - repo: self
    
    variables:
      # Container registry service connection established during pipeline creation
      dockerRegistryServiceConnection: '***'
      imageRepository: 'devops'
      containerRegistry: '***.azurecr.io'
      dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
      tag: '$(Build.BuildId)'
    
    stages:
    - stage: Build
      displayName: Build and push stage
      jobs:
      - job: Build
        displayName: Build
        pool: my-personal-computer
        steps:
        - task: Docker@2
          displayName: Build and push an image to container registry
          inputs:
            command: buildAndPush
            repository: $(imageRepository)
            dockerfile: $(dockerfilePath)
            containerRegistry: $(dockerRegistryServiceConnection)
            tags: $(tag)
    

    I tried to reproduce the problem after the successful runs:

    But nothing... I was unable to reproduce the problem. I have no idea how the problem was fixed. It seems that "pressing the reset button" solves the issue. :)