0

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"
            }
        }
    }
}
2
  • XAML build or task-based build? Commented May 4, 2018 at 14:55
  • Task-based build. Commented May 4, 2018 at 15:05

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! I hadn't thought about inspecting what the browser was doing to discover it's making the same REST calls. I was just going off the documentation.
@Colin The REST API documentation is unfortunately weak in places, especially when you're looking for older API versions. The browser never lies, though.
Thanks, do you know how to do this for overwriting task group variables when queuing a build?
For future folks reaching this: note that the parameters value is a string in JSON format, not an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.