Search code examples
asp.net-coreazure-akscicd

Set AKS ConfigMap data for different environment using CICD pipeline


I am deploying asp.net core application to AKS using Azure CICD pipeline.

I am copying below configMap deployment file from bild and use in release pipeline.

apiVersion: v1
kind: ConfigMap
metadata:
  name: akscicddemo-config
data:
  appsettings.json: |-
    {
      "Logging": {
        "LogLevel": {
         "Default": "Information",
         "Microsoft": "Warning",
         "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "AllowedHosts": "*",
      "AppSettings": {
        "Env": "prod"
        }
    }

Now i want to update above file data with Pipeline Variable. How can we update data in configMap file using release variable based on different environment (stages in pipeline).


Solution

  • I used Replace Tokens in CICD pipeline to replace specific keys from my config.yml file.

    Updated Yml file

      apiVersion: v1
    kind: ConfigMap
    metadata:
      name: akscicddemo-config
    data:
      appsettings.json: |-
        {
          "Logging": {
            "LogLevel": {
             "Default": "Information",
             "Microsoft": "Warning",
             "Microsoft.Hosting.Lifetime": "Information"
            }
          },
          "AllowedHosts": "*",
          "AppSettings": {
            "Env": "#{Env}#"
            }
        }
    

    Replace Tokens Task

    Variable in pipeline