<p>Does anyone have experience in building and pushing docker images + deploying them to AKS via Azure DevOps?</p>

<p>When I build and push an image I can use the variable <code>$(Build.Repository.Name):$(Build.BuildId).</code> </p>

<p>But then I have my <code>.yaml</code> files that I have in my release pipeline to deploy the images.  I cannot (or don't know how) to refer to that variable <code>$(Build.Repository.Name):$(Build.BuildId)</code>.</p>

<p>Does anyone have experience in automating this?</p>

<p>How I got it working for me is by using "tokerisation of the yaml file".</p>

<p>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.</p>

<p>Build image task
<a href="https://i.stack.imgur.com/vNJLR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vNJLR.png" alt="Build image"></a></p>

<p>Push image task</p>

<p><a href="https://i.stack.imgur.com/Bcngl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Bcngl.png" alt="Push image"></a></p>

<p>In the the deployment yaml for the image I refer to:</p>

<p><a href="https://i.stack.imgur.com/ZenUZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZenUZ.png" alt="Deployment yaml"></a></p>

<p>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.</p>

<p><a href="https://i.stack.imgur.com/hRogy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hRogy.png" alt="artifact source name"></a>
<a href="https://i.stack.imgur.com/2eJWX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2eJWX.png" alt="replace token task"></a></p>

<p>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.</p>

<p>See a full example described on <a href="https://medium.com/@marcodesanctis2/a-build-and-release-pipeline-in-vsts-for-docker-and-azure-kubernetes-service-aks-41efc9a0c5c4" rel="nofollow noreferrer">Tokenised version of yaml</a></p>
