Set TFS vNext build variables via the REST API
At $WORKPLACE we're currently busy porting over our XAML builds to the TFS 2015 build system and we wanted to be able to queue another build when the current build completes.
Fortunately for us the REST API makes that a trivial exercise and that particular bit was running fairly quickly.
However...
Because we have a build that will automatically get a version number we needed to pass that version number on to the next build in line. "Aha!", I hear you think, "You can use variables for that!" and yes, you are correct. TFS 2015 allows you, just as in XAML builds, to specify additional variables you can set at queue time.
Alas, the REST API documentation doesn't specify how to do that.
But after a bit of poking around in the JSON data that is returned when you retrieve information about a build I noticed the parameters
property which seemed to contain the variables used at build time.
So when you want to pass variables when queueing a build through the REST API you can use something like this:
{
"definition": {
"id": 25
},
"sourceBranch": "refs/heads/master",
"parameters": "{ \"version\": \"1.2.3.4\" }"
}