In .NET aplication we use the appsettings.json to keep values such as connection string etc for local development mostly. In the context of Azure app servies or containeried envronments etc, we configure mostly app config service (with key vault to manage secrets) to keep our connection information, and any other config values. Howver, sometimes legecy deployments which are still done targeting on premise servers etc might need us to update actual appsetting.josn files or web config files etc. Let's look at how to transform josn files in an Azure pipeline.
The expected outcome
The expectation is transforming the appsettings json file value based on a variable value defined in a release pipeline. We can of cource do the same in YAML pipline as well.
The pipline should substitute the values in json as shown below.
How to do
Assume a josn file is containing below details.
And we just want to replace the default connection string, using a variable value. In a variable group we can define a variable with below name.
ConnectionStrings.DefaultConnection
Then we can use a trasform file task as shown below.
- task: FileTransform@2 displayName: 'File Transform: ' inputs: folderPath: '$(System.DefaultWorkingDirectory)/my_api/v1_API/my_api' jsonTargetFiles: appsettings.json
For the folder path you can provide a web deployment package zip name as below.
- task: FileTransform@2 displayName: 'File Transform: ' inputs: folderPath: '$(System.DefaultWorkingDirectory)/my_api/v1_API/my_api/webapi.zip' jsonTargetFiles: appsettings.json
I
No comments:
Post a Comment