Variable Seeder for Azure DevOps Pipelines
Variable Seeder is a pipeline task (utility) extension for Azure DevOps which takes a json file and create build and deployment pipeline variables based on the JSON.
Benefits
- Same variables may be used for different environments - simply switch by environment variable.
So your pipelines will get environment aware.
- Additionaly all variables are maintained in one place.
Usage
Define a JSON file that contains variables used by a pipeline and specify a value for each environment for example "dev", "test" and "prod".
Example JSON file with variables for each environment
{
"sqls_name":{
"dev" :"dbsrv_dev",
"test": "dbsrv_test",
"prod": "dbsrv_prod"
},
"sqls_username":{
"dev" :"sqlAdmin_dev",
"test": "sqlAdmin_test",
"prod": "sqlAdmin_prod"
},
"db_name":{
"dev" :"OnTrackConnectorDB_dev",
"test": "OnTrackConnectorDB_test",
"prod": "OnTrackConnectorDB_prod"
},
"db_sku":{
"dev" :"Basic_dev",
"test": "Basic_test",
"prod": "Basic_prod"
},
"auditDB_retentionDays":{
"dev" :"0 dev",
"test": "0 test",
"prod": "20 prod"
}
}
Parameters
Configure Variable-Seeder with a display name, the file name of the varibale JSON and a environment that should be used:
- displayName the name for the task
- jsonFilePath the JSON file that contains the variables for each environment
- environment: a specific environemnt to be used for further pipeline commands
Result
The variables are set and may be used in a powershell script like this:
Write-Host "$(db_sku)"
Write-Host "$(sqls_name)"
YAML Notation
The full pipeline YAML file may look like this:
steps:
- task: whiteduck-software.devops-variable-seeder.variableseeder.variableseeder@1
displayName: 'Seed environemnt variables'
inputs:
jsonFilePath: 'tests/bsp_variables.json'
environment: test
steps:
- powershell: |
Write-Host "$(db_sku)"
Write-Host "$(sqls_name)"
displayName: 'PowerShell Script'