Reputation: 1
I would like to create a pipeline that backup databases on different servers (each server is a different country). I am thinking that the Stage/step/job for each country will have to be computed by dynamically referenced Agent.Name which will run on different servers based on the country.
Also other country related variables will have to be defined in a template like ${{parameters.country}}_variables.yml
.
Another thing is that the pipeline has to be cron scheduled, so it would have to run iteratively for all countries, which means that It has to fetch the ${{parameters.country}}_variables.yml
file, run the backup task with the defined variables on the correct Agent.Name and then do the whole thing again for the next country.
I am kinda lost. Any help would be appreciated
I already tried different approaches but never managed to dynamically call the template ${{parameters.country}}_variables.yml
Also it seems that I cannot manage to run the backup job iteratively for every country
Upvotes: 0
Views: 124
Reputation: 13824
You can set your YAML pipeline like as below.
parameters:
- name: countryList
type: object
default:
- country1
- country2
. . .
- countryN
stages:
- ${{ each country in parameters.countryList }}:
- stage: DB_${{ country }}
displayName: 'Stage: DB for ${{ country }}'
variables:
- template: ${{ country }}_variables.yml
jobs:
# Jobs and steps to backup DB.
- job: backupDB
displayName: 'Job: Backup DB for ${{ country }}'
With this configuration, when running this YAML pipeline, it will automatically generate a copy of the same stage for each value of parameters.countryList
. Each copied stage will use the associated single value.
Of course, you also can set the copy on the job-level rather than stage-level based on your actual needs.
parameters:
- name: countryList
type: object
default:
- country1
- country2
. . .
- countryN
stages:
- stage: backupDB
displayName: 'Stage: Backup DB'
jobs:
- ${{ each country in parameters.countryList }}:
- job: DB_${{ country }}
displayName: 'Job: Backup DB for ${{ country }}'
variables:
- template: ${{ country }}_variables.yml
steps:
# Steps to backup DB.
This will automatically generate a copy of the same job for each value of parameters.countryList
. All the copied jobs are in the same stage.
Upvotes: 0