I have a long-running DevOps pipeline that sets up a complex environment every morning.
It has a parameter; let's call it "Version."
I need to schedule the pipeline to run three times each morning with Version values 1, 2, and 3 automatically.
Looking through the triggers, neither a schedule trigger nor a pipeline trigger seems to allow to pass a parameter value.
Is there a way to do that? Important is that they run independently of each other. Each execution takes between 30 and 60 minutes. So running them in a loop one after each other is not an option.
This is what my YAML code currently looks like:
trigger: none
pr: none
schedules:
- cron: 0,5,10 12 * * mon,tue,wed,fri
displayName: Scheduled most mornings
branches:
include:
- CIBranch
always: true
parameters:
- name: Version
type: string
default: '3'
If you want to run three times the same build changing just a parameter, you shoudl consider moving main steps to template. It may look like that:
#template.yaml
parameters:
- name: 'Versions'
type: object
default: {}
- name: 'server'
type: string
default: ''
steps:
- ${{ each version in parameters.Versions }}:
- script: echo ${{ parameters.server }}:${{ version }}
- script: echo ${{ parameters.server }}:${{ version }}
- script: echo ${{ parameters.server }}:${{ version }}
- script: echo ${{ parameters.server }}:${{ version }}
- script: echo ${{ parameters.server }}:${{ version }}
- script: echo ${{ parameters.server }}:${{ version }}
Build definition:
trigger: none
pr: none
schedules:
- cron: 0,5,10 12 * * mon,tue,wed,fri
displayName: Scheduled most mornings
branches:
include:
- master
always: true
pool:
vmImage: 'ubuntu-latest'
steps:
- template: template.yaml
parameters:
Versions:
- "1"
- "2"
- "3"
server: someServer
While passing different parameters seems not possible, there is a way to achieve this.
In the yaml file, use the strategy section like this:
pool:
vmImage: 'vs2017-win2016'
strategy:
matrix:
Run1:
myvar: 12
Run2:
myvar: 14
Run3:
myvar: 16
This will create three "runs" setting myvar
as an environment variable.
See Azure DevOps / Azure Pipelines / Pipeline basics / Jobs & stages / Define container jobs # Multiple Jobs for details. (Note: While this documentation talks about containers, this works without containers as well.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With