TFS 2017 API;使用变量排队构建 [英] TFS 2017 API; Queuing a build with variables

查看:19
本文介绍了TFS 2017 API;使用变量排队构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建构建请求并为 TFS 构建定义中定义的自定义变量指定新值.我假设我可以在不更新构建定义的情况下做到这一点.我将以下 JSON 发布到 URL:http:///tfs/DefaultCollection//_apis/build/builds?api-version=3.1.构建排队但传入的变量值没有覆盖默认值.我错过了什么?我需要以不同的方式指定变量名称吗?

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

推荐答案

您提供了错误的 JSON 结构.它是参数,而不是变量,并且您指定键/值对的方式不正确.

You're providing the wrong JSON structure. It's parameters, not variables, and the way you're specifying the key/value pairs is incorrect.

这个 PowerShell 代码段应该为您指明正确的方向:

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)

就其价值而言,通过在浏览器中打开开发人员工具并查看 TFS UI 进行的 REST 调用,发现这种事情是微不足道的.有时文档不清楚(就像在这种情况下一样),但是当您复制应用程序进行的相同 REST 调用时,很难混淆.

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.

这篇关于TFS 2017 API;使用变量排队构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆