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.
3 Answers
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.
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:
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
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.