How to get the currentSlot and change the helm upgrade command with the new slot on Azure devops?

11/28/2019

I am trying to implement CI/CD pipeline for my APIs on AKS. i have successfully configured the CI and CD pipelines which works quite smoothly, now i have 2 environments named Prod and Slot to enable 0 down time.

I found the blue/green deployment method. And in my CD pipeline i am trying to set the current slot and pass it to the helm upgrade command in the next step

currentSlot=`(helm --client-only get values --all api-poi | grep -Po 'productionSlot: \K.*')`

if [ "$currentSlot" == "blue" ]; then
    newSlot="green"
else
    newSlot="blue"
fi

but it always set the newslot as empty. what could be the reason?

$(newSlot).enabled=true
-- devops azure
azure
azure-aks
azure-devops
kubernetes

1 Answer

11/28/2019

Try with Azure CLI command instead of Bash script with the az aks get-credentials --name involved.

Alternate CLI command would be

az aks get-credentials --name $(AKSClusterName) --resource-group $(AKSResourceGroup)
currentSlot=$(helm get values --all $(chartName) |  grep -oP '(?<=productionSlot: ).*')
if [ "$currentSlot" == "blue" ]; then
    newSlot="green"
else
    newSlot="blue"
fi

you need to set those AKSClusterName,AKSResourceGroup,chartName values in the pipeline or hard code them

-- Sajeetharan
Source: StackOverflow