Retrieve image digest value from Docker task inside azure pipelines

Viewed 378

I am using Azure Pipelines (with YAML format) to build Dockerfile and push the image to Azure Container Registry.

Here is part of the YAML definition:

- task: Docker@2
  displayName: Build Dockerfile
  inputs:
    command: 'build'
    containerRegistry: 'containerRegistry'
    repository: '$(imageRepository)'
    Dockerfile: 'src/Api/Dockerfile'
    buildContext: '.'
    tags: '$(imageTag)'

- task: Docker@2
  displayName: Push image
  inputs:
    command: push
    containerRegistry: 'containerRegistry'
    repository: '$(imageRepository)'
    tags: '$(imageTag)'

So my question is, is there a way to retrieve the digest value on docker push task, so I can use it in the next tasks?

It seems that in the older versions of the Docker task, that was possible and there was a task parameter imageDigestFile, I am referring to Docker@0.

Unfortunately now that looks deprecated and I can't find a way to do it using the latest version.

Thanks!

Best regards, Nikolay

1 Answers

Unfortunately now that looks deprecated and I can't find a way to do it using the latest version.

This is a known issue for the latest version of docker push task:

How to use output of DockerV2 task

That because that product team have tried to limit the number of inputs to the task to simplify it in DockerV2. So they have not provided the support for image digest files. But image digest is written to the output called DockerOutput.

The source code here.

And the product team will work with the people involved in the design of this task and see how to do this work.

To resolve this issue, we could try to use the older versions of the Docker task or parse the output DockerOutput and fetch the image digest

Related