Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start a build and passing variables through Azure DevOps Rest API

I would like to start a Azure Pipelines build through the REST API. There is an API for queuing builds but I couldn't find a way to define variables.

like image 365
Pascal Berger Avatar asked Dec 17 '15 19:12

Pascal Berger


People also ask

How do you pass variables between tasks in Azure DevOps?

Logging command called task. setvariable lets us pass variables across Tasks. Task. setvariable sets the value to a variable which by default can be used in any Task within a Job or across the Jobs of a given Stage.

How do you pass variables in Azure release pipeline?

Passing variables between tasks in the same job For example, to pass the variable FOO between scripts: Set the value with the command echo "##vso[task. setvariable variable=FOO]some value" In subsequent tasks, you can use the $(FOO) syntax to have Azure Pipelines replace the variable with some value.

How do you trigger build on PR Azure DevOps?

Create a pull request trigger You can set up pull request triggers for both Azure Repos or GitHub repositories. From within your project, Select Pipelines > Releases, and then select your release pipeline. Under the Pull request trigger section, select the toggle button to enable it.


1 Answers

The accepted answer does not really answers the question when you need to set a value at queue time. The solution is actually pretty simple you just have to add a parameters field to the json payload. The content should be a json string (not directly an object) containing the parameters Ex :

{
    "parameters":  "{\"ReleaseNumber\":  \"1.0.50\", \"AnotherParameter\":  \"a value\"}",
    "definition":  {
                       "id":  2
                   }
}

EDIT : This feature is now properly documented as an optional stringified dictionary. See https://www.visualstudio.com/fr-fr/docs/integrate/api/build/builds#queue-a-build

like image 159
Cyprien Autexier Avatar answered Oct 23 '22 00:10

Cyprien Autexier