I have some code that loop through some values utilising templates. My issue is the jobs all run randomly so I want to create some dependencies, but because they are in a for loop I have not been able to work out how I can name the job steps to then utilise the "dependsOn" option. Also if I tried to hard code a job name I get a duplicate job name error.
patch-tasks.yml
jobs:
- job: '${{ parameters.sqlserver }}_A'
displayName: '${{ parameters.sqlserver }}--set-up-stuff'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "Patchgroup '${{ parameters.patchgroup }}'"
Write-Host "sqlserver '${{ parameters.sqlserver }}'"
- job: '${{ parameters.sqlserver }}_B'
displayName: '${{ parameters.sqlserver }}--set-up-morestuff'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host "Patchgroup '${{ parameters.patchgroup }}'"
Write-Host "sqlserver '${{ parameters.sqlserver }}'"
patch-template.yml
parameters:
- name: sqlservers
type: object
default: []
- name: patchgroup
type: string
default: ''
jobs:
- ${{ each sqlserver in parameters.sqlservers }}:
- template: patch-tasks.yml
parameters:
sqlserver: ${{ sqlserver }}
patchgroup: ${{ parameters.patchgroup }}
pipeline script
trigger: none
parameters:
- name: InstanceArgs
type: object
default: []
variables:
patchgroup: test
jobs:
- template: patch-template.yml
parameters:
patchgroup: $(patchgroup)
sqlservers: ${{ parameters.InstanceArgs }}