1

Not able to find a way pass image from ACR as artifact to Azure DevOps pipeline JSON.
In other words, I am trying to replicate artifact from Azure DevOps Releases(see attached image), want user to have option to select image from ACR while running the JSON pipeline.

Image from ACR as artifact in Azure DevOps Releases

  • Hi Did you get a chance to check out below answer? How did it go? Could you please accept it as answer if it worked out. – Levi Lu-MSFT Feb 22 '21 at 08:14

3 Answers3

0

You can use a Container Resource Block

You can use a first class container resource type for Azure Container Registry (ACR) to consume your ACR images. This resources type can be used as part of your jobs and also to enable automatic pipeline triggers.

trigger:
  - none # Disbale trigger on the repository itself

resources:       
  containers:
  - container: string # identifier for the container resource      
    type: ACR 
    azureSubscription: string # Azure subscription (ARM service connection) for container registry;
    resourceGroup: string # resource group for your ACR
    registry: string # registry for container images
    repository: string # name of the container image repository in ACR
    trigger: true

If you wnat to trigger only on certain tags (or exclude certain tags) you can replace the trigger value like below

trigger:
  tags:
    include: [ string ]  # image tags to consider the trigger events, defaults to any new tag
    exclude: [ string ]  # image tags on discard the trigger events, defaults to none

A complete pipeline example:

trigger:
  - none # Disable trigger on the repository itself

resources:       
  containers:
  - container: myId # identifier for the container resource      
    type: ACR 
    azureSubscription: test # Azure subscription (ARM service connection) for container registry;
    resourceGroup: registry # resource group for your ACR
    registry: myregistry # registry for container images
    repository: hello-world # name of the container image repository in ACR
    trigger: true

pool:
  vmImage: 'ubuntu-latest'

steps:
- bash: |
    echo "The registry is: $(resources.container.myId.registry)"
    echo "The repository is: $(resources.container.myId.repository)"
    echo "The tag is: $(resources.container.myId.tag)"

If you push anew image to the helloworld repository the pipeline will start

docker pull hello-world:latest
docker tag hello-world:latest myregistry.azurecr.io/hello-world:newtag
docker push hello-world:latest myregistry.azurecr.io/hello-world:newtag

The result of the script step is

The registry is: myregistry
The repository is: hello-world
The tag is: newtag
danielorn
  • 5,254
  • 1
  • 18
  • 31
  • Hi Danielorn. Thanks but rerources.containers is used to run your build stages in that container. I don't want to do that, wan't to pass image tag & deploy that image. So image is an artifact for my pipeline. – vibhore miglani Mar 04 '21 at 13:26
  • @vibhoremiglani That is exactly what my example does. It triggers when a new tag is pushed to the repository specified and you can then access the registry, repository name and tag name and use that to pull or deploy the image. – danielorn Mar 04 '21 at 16:15
0

You can use the container resources to consume a container image as part of your yaml pipeline. And you can use runtime parameters to allow user to select the images while running the pipeline. See below example:

1, Define runtime parameters to let user select the images.

parameters:
- name: ACRimage
  type: string
  default: image1
  values:
  - image1
  - image2
  - image3

Then when clicking the Run to run the pipeline, user will be given the option to select which image to use in the pipeline.

enter image description here

2, Add ACR container resources in your pipeline.

Before you can add ACR container resource. You need to create Docker Registry service connection

Then you can define the container resource in your pipeline like below:

resources:
  containers:
  - container: ACRimage
    image: ${{parameters.ACRimage}}
    endpoint: ACR-service-connection

So the full yaml pipeline looks like below:

parameters:
- name: ACRimage
  type: string
  default: image1
  values:
  - image1
  - image2
  - image3

resources:
  containers:
  - container: ACRimage
    image: ${{parameters.ACRimage}}
    endpoint: ACR-service-connection

trigger: none

pool:
  vmImage: 'ubuntu-latest'

steps:
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • Thanks Levi. Your suggestion to populate image tags as list values might be helpful, but currently the list of tags needs to be updated dynamically for my use case. I didn't found any way to dynamically update this list of tag with actual list of tags in ACR. If I do, will update my answer. – vibhore miglani Mar 04 '21 at 13:32
-1

Sorry to inform this but azure yaml pipelines doesn't support this.

What danielorn suggested 'rerources.containers', that is used to run your build stages in that container. I don't want to do that. Aim is to deploy take image tag from user & deploy that image. So need image needs to be passed as artifact just like in Release pipeline. Sadly this is not supported as of now in YAMl pipelines, I got a confirmation azure team.

  • 1
    Your statement "`resources.containers`, that is used to run your build stages in that container" is simply not correct, you are confusing it with `jobs.container`, which fits your description. In my example you can see how you can trigger the pipeline on image change and access the image tag that triggered the pipeline – danielorn Mar 04 '21 at 16:27
  • 1
    Your description of what you want to achieve is also a bit unclear, do you want to trigger the pipeline on image change (like you trigger a pipeline when an artifact is updated) or do you simply provide the user with a dropdown populated with all tags for a certain image? – danielorn Mar 04 '21 at 16:29