0

I am building and pushing Docker images to my Azure Container Registry from Azure DevOps using the azure-pipelines.yml file below.

This works great except that there doesn't seem to be any relation created between the created image and the pipeline that created it. There is no artifacts listed on the executed pipeline:

Screenshot of executed pipeline in DevOps showing "0 work items" below the Related section

The artifact is created correctly such that I can use it when running a release pipeline and if I inspect the image locally I can confirm that it has the labels on it created by the Docker task as described here.

# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- none

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '<my connection>'
  imageRepository: '<my repo>'
  containerRegistry: '<my registry>'
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  tag: '$(Build.BuildNumber)'
  DOCKER_BUILDKIT: 1

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build and push stage
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)
    steps:
      - task: Docker@2
        displayName: Build
        inputs:
          command: build
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          arguments: '--target prod'
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: |
            latest
            $(tag)
      - task: Docker@2
        displayName: Push
        inputs:
          command: push
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: |
            latest
            $(tag)

3 Answers 3

0

You should not see that. Artifact is something published from PublishBuildArtifacts@1 task. In your case, you publish to Docker Container Registry (not to azure build artifacts).

All other items (like tags and new image) you can find through docker cli.

0

As my experience, Artifact of the Build pipeline in a Docker solution are normally a Docker Compose file, or manifest file... that contains information about the images have been built. Then, in the Release pipeline we can use these files for deploying corresponding images to the server. You have to pusblish these files as an Artifact by yourself.

0

Shamrai is correct that the build and push tasks for Docker don't publish an artifact to the pipeline and instead are pushing that artifact to ACR.

If you want to see the artifact in the pipeline you will have to use the PublishBuildArtifacts task.

However, if you only want a link between the build and the image and do not want to store a second copy in the build, you could tag the image with the build id.

- task: Docker@2
        displayName: Push
        inputs:
          command: push
          repository: $(imageRepository)
          dockerfile: $(dockerfilePath)
          containerRegistry: $(dockerRegistryServiceConnection)
          tags: |
            latest
            $(tag)
            $(Build.BuildId)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.