I have a task template that is a PowerShell task that needs 3 parameters.
parameters:
param1: ''
param2: ''
param3: ''
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: | [string[]] $SqlCmdVariables = "${{ parameters.param1 }}" -split "," | ForEach-Object { $_.trim() }
[string] $file = "${{ parameters.param2 }}/${{ parameters.param3 }}" -replace "/", ""
I have a job template taht uses the task template like
jobs:
- deployment: DeploymentTest
pool:
name: Default
strategy:
runOnce:
deploy:
steps:
- template: ../../Template/Step/runPowerShellDeployment.yml
parameters:
param1: 'dbName=DbNameEnvA secondDbName=AnotherDBInEnvA'
param2: 'someScriptFile.sql'
param3: 'InstanceA'
- template: ../../Template/Step/runPowerShellDeployment.yml
parameters:
param1: 'dbName=DbTestNameEnvA secondDbName=AnotherTestDBInEnvA thirdDb=YetAnotherDbInEnvA'
param2: 'someScriptFile.sql'
param3: 'InstanceATest'
- template: ../../Template/Step/runPowerShellDeployment.yml
parameters:
param1: 'dbName=DbCucumberTestNameEnvA secondDbName=AnotherCucumberTestDBInEnvA OtherParam=JustToShowThatParam1IsJustAString'
param2: 'someScriptFile.sql'
param3: 'InstanceACucumberTest'
What I would like to do is to use a loop for each environment and define the parameters in separate files (envA.yml, envB.yml, etc.). But I’m not sure about how to define the parameter values in the files and how to read it in the new template like here for param1, param2 and param3 :
parameters:
- name: environmentsToDeploy
type: object
default:
- EnvironmentA
- EnvironmentB
jobs:
- deployment: DeploymentTest
pool:
name: Default
strategy:
runOnce:
deploy:
steps:
steps:
- ${{ each value in parameters.environmentsToDeploy }}:
- template: ../../Template/Step/runPowerShellDeployment.yml
parameters:
param1:
param2:
param3: