0
votes

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 user trigger the pipeline with env of his choice, that doesn't have any problem,

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
2
Can we do it using Azure devops API ?saikumar reddy
Hi @saikumarreddy, How are things going? Is the suggestion in my answer helpful to you? Please have a try with it. Any update, feel free to tell us. Thanks.Bright Ran-MSFT

2 Answers

0
votes

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".

0
votes

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"

} }'