'Schedule Azure DevpOs pipeline with two different parameters according to the cron syntax

I'm working on Azure DevOps Pipeline to schedule a pipeline with two different parameters on different days according to the cron syntax.

Looking through the triggers, conditions, neither a schedule trigger nor a pipeline trigger seems to allow to pass a parameter value. Below are my parameters. Usually a user will trigger the pipeline with an environment of his choice; that doesn't have any problems.

parameters:
  - name: environment
    displayName: Select the Suite to execute
    default: Test
    values:
    - Test
    - Dev
    - QA

How do I add parameters to pipeline on a schedule with parameters?

schedules:
- cron: "0 1 10-15 * sat"
  displayName: 7PM CST - SAT
  branches:
    include:
    - feature
- cron: "0 3 25-31 * sat"
  displayName: 9PM CST - SAT
  branches:
    include:
    - feature

Also checked options with strategy which doesn't satisfy my need, where I cannot have a new job to have the scheduled run with parameters as below, as this pipeline needs to be available for users to trigger based on the environment selection, if I specify these conditions jobs/tasks won't trigger.

pool:
  vmImage: '**'
strategy:
  matrix:
    Run1:
      myvar: 12
    Run2:
      myvar: 14
    Run3:
      myvar: 16


Solution 1:[1]

I was able to trigger Pipeline Passing parameters (browser,environment) from the API call as below

curl -L -X POST 'https://dev.azure.com/Org/project/_apis/build/builds?definitionId-**&api-version=6.1-preview.6' -H 'Authorization: $(ADO__AUTH)' -H 'Content-Type: application/json' --data

'{"definition": {

"id": 825

}, "resources": {

   "repositories": {

    "self": {

    "refName": "refs/heads/develop"

     }
   }
},

  "templateParameters": {

            "browser":"chrome",

            "environment": "Test"

} }'

Solution 2:[2]

We seem have not method to automatically and dynamically change the value of a parameter during the pipeline run.

As a workaround, you can try set up a previous job and add the following steps in this job:

  1. Execute the API "Builds - Get", if the build run is triggered by a scheduled trigger, from the Response of the API call, you can get the name of the scheduled trigger (triggerInfo.scheduleName). In your case the name is either "7PM CST - SAT" or "9PM CST - SAT".

  2. According to the 'scheduleName' returned by the API call, you can use the Logging command "SetVariable" to set an output variable with the value that you want to set it as the environment.

  3. Then in the subsequent jobs that depend on the previous job, you can use the output variable. For more details, you can see "Set a multi-job output variable".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 saikumar reddy
Solution 2 Bright Ran-MSFT