-1

my build pipeline is in azureDevopsservices and my release pipeline in azuredevopsServer

build pipeline is creating docker image and keeping in image azure container registry and working fine

release pipeline is deploying docker image in AKS cluster with the help deployment object enter image description here

but i am unable to replace image tag in my deployment file dynamically.

what i am looking for is once the build pipeline is done, release pipeline should trigger automcatically and it should replace the docker tag automatically.

enter image description here

I have tried using replace token task as well but it not working.

enter image description here

Satyam Pandey
  • 593
  • 2
  • 10
  • 32
  • What inputs are you providing? What does your deployment manifest working? What do you mean by "isn't working"? Do you get an error message? – Daniel Mann Feb 21 '21 at 15:55
  • deployment manifest is working it picking the same image what i am specifying example image:mycontainerregistry/myapp:20210221.3 – Satyam Pandey Feb 22 '21 at 01:25

1 Answers1

0

Based on your requirement, you could refer to the following process to automatically trigger the release on Azure Devops server and replace the tag with the variable.

my build pipeline is in azureDevopsservices and my release pipeline in azuredevopsServer

To automatically trigger the release in Azure Devops Server, you can refer to my reply in your other ticket.

Replace docker tag in release pipeline

As far as I know, the Replace token task can meet your requirement.

From your docker tag format, it seems that this is the $(build.buildnumber) variable in Azure Devops Service Build Pipeline.

  1. You could set the variable in Release Pipeline and set Settable at release time option.

enter image description here

  1. In deployment manifest, you could set the image with the following format: image:mycontainerregistry/myapp:#{Version}#

  2. Use the Replace token task and select the target file.

enter image description here

  1. When you use Rest API to trigger the release , you could pass the varible to release pipeline at the same time.

Here is the sample:

$token = "PAT"

$url = "https://{instance}/{collection}/{project}/_apis/release/releases?api-version=5.0"

$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))

$JSON = @'
{
   "definitionId": ID,
  "variables": {
       "Version": {
         "value": "$(Build.buildnumber)"
       }
 
   }
}
'@
     
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -ContentType application/json -body $JSON
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28