Reputation: 11813
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'
Upvotes: 14
Views: 16087
Reputation: 277
You could simply use loop on stage or job and still achieve desired outcome
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: '1,2,3'
stages:
- ${{ each version in split(parameters.Version, ',') }}:
- stage: Running_For_${{ version }}
displayName: 'Running - ${{ version }}'
dependsOn: []
jobs:
- job:
steps:
- script: echo "Hello World"
dependsOn: []
to run all your stages in parallel.
Upvotes: 1
Reputation: 649
Another solution to handle this limitation by Azure Dev Ops is to create a kind of new "wrapper" build pipeline that triggers parameterized your desired build pipeline by using this custom build task "Trigger Build Task". This task allows you to trigger builds with parameters and offers a few more trigger options. You can schedule the "wrapper" build as you now it and create a task for each desired parameterized build to be triggered.
Upvotes: 0
Reputation: 11813
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.)
Upvotes: 4
Reputation: 76986
Pass different parameter value to Azure DevOps Pipeline based on schedule
I am afraid there is no such out of box way to achieve this.
As workaround, you could try to use Azure DevOps counter to set the version from 1-3
for each scheduled build, like:
variables:
internalVersion: 1
semanticVersion: $[counter(variables['internalVersion'], 1)]
Then we could create powershell scripts to determine whether the counter
value is equal to 3
, if so, call the REST API Definitions - Reset Counter to reset the counter variable Value and return the seed.
Hope this helps.
Upvotes: 0
Reputation: 40939
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
Upvotes: 4