'Azure Devops Build: parameters for scheduled builds
Is there any way to pass parameters to azure devops build pipelines (YAML) when triggered on a schedule? E.g. if you want to build a release build nightly, but also a debug build weekly for example?
It doesn't seem right to have to duplicate the whole build pipeline to SomeBuild-Debug in order to make a build that has configuration=debug as default, to be able to schedule it?
Solution 1:[1]
I came across this recently and I think there is. If you have access to the azure portal you could create an Azure Logic App that triggers on a schedule, and can start a "queue a new build". It allows for a json dictionary of parameters:
This allows to start the build with different parameters.
Solution 2:[2]
It's possible to detect that a build was triggered via a schedule. Based on this information, you can set certain variables or trigger certain processes.
Azure DevOps pipelines give you access to a bunch of predefined variables. In particular, Build.Reason:
The event that caused the build to run.
Manual: A user manually queued the build.IndividualCI: Continuous integration (CI) triggered by a Git push or a TFVC check-in.BatchedCI: Continuous integration (CI) triggered by a Git push or a TFVC check-in, and the Batch changes was selected.Schedule: Scheduled trigger.ValidateShelveset: A user manually queued the build of a specific TFVC shelveset.CheckInShelveset: Gated check-in trigger.PullRequest: The build was triggered by a Git branch policy that requires a build.ResourceTrigger: The build was triggered by a resource trigger or it was triggered by another build.
Based on this variable, it's possible to define a custom one:
variables:
${{ if eq( variables['Build.Reason'], 'Schedule' ) }}:
myCustomVariable: 'Weekly debug'
or trigger a custom process:
- task: CmdLine@2
condition: eq( variables['Build.Reason'], 'Schedule' ))
displayName: 'My scheduled script'
inputs:
script: echo "I was launched during a scheduled build"
Credit: this answer is inspired by Kevin Lu-MSFT'sanswer on Setting parameter value dynamically for automatic pipelines
Solution 3:[3]
You can schedule an Azure DevOps build using an external service (ansible, automated task, etc) by using a REST API. In the rest API call you can specify the input parameters. This way you will need to schedule the trigger of the build pipeline using the external service and not schedule of the .yml file.
Example of triggering a build pipeline. You should replace the characters between **
POST https://dev.azure.com/**GeralexGR**/**test-project**/_apis/pipelines/**11**/runs?&api-version=6.1-preview.1
Body section
Keep in mind that you will also need authentication using a PAT to use the REST API of Azure Devops.
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 | GetShifting |
| Solution 2 | Métoule |
| Solution 3 | GeralexGR |


