Does anyone have experience in building and pushing docker images + deploying them to AKS via Azure DevOps?
When I build and push an image I can use the variable $(Build.Repository.Name):$(Build.BuildId).
But then I have my .yaml
files that I have in my release pipeline to deploy the images. I cannot (or don't know how) to refer to that variable $(Build.Repository.Name):$(Build.BuildId)
.
Does anyone have experience in automating this?
How I got it working for me is by using "tokerisation of the yaml file".
During the build fase (build and push of the image to the private repo I use a default variable in Azure Devops, $(Build.BuidId), as tag for the docker image.
Push image task
In the the deployment yaml for the image I refer to:
Then for the deployment before I apply the yaml files, with kubectl apply task, I use the task "Replace tokens". You can specify which files to replace tokens in. Since I only used a token for the image I only selected the deployment yaml file.
What it does it replaces #{Release.Artifacts.acpyaml.BuildId}# with the actual build nr of the last build, so when it starts pulling the image it has the right tag.
See a full example described on Tokenised version of yaml
If you have on the release pipeline only 1 artifact so you can use the variables also in the release in the same way ($(Build.Repository.Name):$(Build.BuildId)
).
If you more then 1 artifact the variables will refer to your primary artifacts:
If you want to use the variables to other artifacts (not the primary) you can use this way:
Release.Artifacts.{alias}.BuildId
The {alias}
is the alias name of the artifacts: