This task allows you to substitute variables in JSON files. It's particularly useful for replacing configuration values in settings files during deployment.
Features
Replace JSON keys with values from pipeline variables
Support for boolean, number, and string values
Recursive file search
Configurable error handling for missing variables
Configurable logging levels
How to Use
Add the task to your pipeline
Configure the files to process
Define your replacements
Example
steps:
- task: VariableSubstitution@1
inputs:
files: "**/appsettings.json" # Process all appsettings.json files
replacements: |
EnvironmentSettings.Local: false
TableSettings.TablePrefixEnv: TABLE_NAME_PREFIX
Migrations.InitalizeTables: false
Migrations.SeedDatabase: true
Cors.AllowedOrigins.0: https://example.com
Serilog.MinimumLevel: Information
logLevel: info # Optional: control logging verbosity