TFS 2017 API; Queuing a build with variables

℡╲_俬逩灬. 提交于 2019-12-11 16:49:45

问题


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"
            }
        }
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/50176797/tfs-2017-api-queuing-a-build-with-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!