0

I have created a ASP.NET Core WebAPI and deployed in an Dev Environment (Kubernetes) using Azure Pipelines. How can I update the configuration in the pipeline if I need to publish the same API in another environment (eg. SIT). Since I have different settings/configuration for Dev and SIT environments. Kindly guide me.

Sreelal T
  • 21
  • 2
  • Not get your response for several days. What configuration do you want to update, please describe in detail. – Hugh Lin Jan 14 '20 at 07:52
  • @HughLin-MSFT, Sorry for the late response. I am delpoying the API to a Kubernetes Cluster using AKS through Azure Pipelines. The database connection strings are in 'appsettings.json'. The problem occurs when I want to deploy the same API to other environments like QA/UAT/Prod. Since each environment is having separate databases. – Sreelal T Jan 15 '20 at 05:01
  • You can use `Replace Tokens` extension to replace the database connection string in appsettings.json. Please view the below answer. – Hugh Lin Jan 17 '20 at 08:51

2 Answers2

0

The problem occurs when I want to deploy the same API to other environments like QA/UAT/Prod. Since each environment is having separate databases

For this issue , there are several ways to achieve this. You can add Replace Tokens extension to the job to replace the database connection string in appsettings.json.

enter image description here

You can define your variable like below:

{
  "ConnectionStrings": {
    "DefaultConnection": "#{connectstring}#"
  }
}

You can refer to this case and lab for details.

Here are some reference for the same issue:

Replacing database connection strings in the Docker image

Set Json Property task to replace the ConnectionStrings

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • If this is the case, we might need different build pipelines for each environment right? – Sreelal T Jan 17 '20 at 09:25
  • I think it is not necessary to use different build pipelines,you just need to replace different connection string in `replace tokens` task .Then generate different artifacts, choose different artifacts in the release to deploy to the corresponding environment. – Hugh Lin Jan 17 '20 at 09:41
  • Replace tokens in 'appsetting.json' will not work. Because in build pipeline I am pushing the Image to ACR with the replaced values. And I have only one build pipeline. In release pipeline I am deploying in to multiple environments using AKS. So same appsettings will be getting deployed in all the environments. – Sreelal T Jan 21 '20 at 04:44
  • You can set approvals for the stages to control which environment to deploy to.Please refer to [this](https://learn.microsoft.com/en-us/azure/devops/pipelines/release/approvals/index?view=azure-devops). – Hugh Lin Jan 21 '20 at 10:06