I am trying to create a build request and specify new values for custom variables defined in the TFS build definition. I assume I can do this without updating the build definition first. I posted the following JSON to the URL: http://<server-name>/tfs/DefaultCollection/<project-name>/_apis/build/builds?api-version=3.1
. The build queued up but the variable value passed in did not override the default value. What am I missing? Do I need to specify the variable name differently?
{
"definition": {
"id": 24,
"variables": {
"IssueNumber": {
"value": "98765"
}
}
}
}
You're providing the wrong JSON structure. It's parameters
, not variables
, and the way you're specifying the key/value pairs is incorrect.
This PowerShell snippet should point you in the right direction:
$url = 'http://test-tfs-instance:8080/tfs/myCollection'
$body = @{
definition = @{
id = 1435
}
parameters = '{"MyParam":"OverriddenValue","system.debug":"false"}'
}
Invoke-RestMethod -Uri "$($url)/TeamProject/_apis/build/builds?api-version=3.1" -UseDefaultCredentials -Method Post -ContentType 'application/json' -body ($body | convertto-json -Compress -Depth 10)
For what it's worth, this kind of thing is trivial to discover by opening up the developer tools in your browser and looking at the REST call the TFS UI makes. Sometimes the documentation is unclear (as it is in this case), but it's hard to get mixed up when you're copying the same REST calls the application makes.