如何正确传递变量& TFS 2015中API 2.0 VNext Build的原始版本 [英] How to correctly pass variables & source version to API 2.0 VNext Build in TFS 2015

查看:162
本文介绍了如何正确传递变量& TFS 2015中API 2.0 VNext Build的原始版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到将定义的变量构建定义参数传递给带有TFS 2015的新API 2.0构建引擎的正确方法. 内部部署TFS 2015 Update 3 .

I'm having difficulty finding how the correct way to pass defined variables and build definition arguments to the new API 2.0 build engine with TFS 2015. I'm using TFS 2015 Update 3 on-premise .

我已使用如下所示的powershell触发了POST:

I've triggered a POST with powershell that looks like this:

$Build_Definition_ID = 1234
$TFSInstanceURL = 'http://tfsservername:port/tfs'
$ProjectCollection = 'CollectionName'
$TeamProject = 'ProjectName'
$Changeset = "12345"
$UserName = "$env:USERDOMAIN\$env:USERNAME"
$UserNamePartial = $env:USERNAME


$body = @"
   {
       "definition": {
           "id": "$Build_Definition_ID"
       }
   }
"@

$baseUri = $TFSInstanceURL+"/"+$ProjectCollection+"/"+$TeamProject+"/_apis/build"
$postUri = $baseUri+"/builds?api-version=2.0"

##Create a new PSCredential based on username/password
$User =  'foo\bar'
$Password  =  'examplepass' 
$securePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($User, $securePassword)

### Queue a build ###
##Call the REST API for TFS that does a POST request to queue a build with the body of the request to be the build definition
$buildResponse = Invoke-RestMethod -Method POST -Credential $credential -ContentType application/json -Uri $postUri -Body $body

#Write-Host (ConvertTo-Json $buildResponse)
#ConvertTo-Json $buildResponse | out-file  -FilePath $Changeset-ResponseJson.json -Force

powershell脚本成功启动了定义.但是,我仍然没有成功: -传递我要针对的特定源版本(示例C12345) -传递自定义变量值

The powershell script is successfully launching the definition. However, I'm still not successfully: - Passing in the specific source version I want to run against (example C12345) - Passing in the custom variable values

另外: 如果您知道传递参数的正确方法,例如要从源映射的文件夹(以允许动态选择不同的分支),那么这将有所帮助.

Additionally: If you know of the proper way to pass in the arguments such as the folder to map from source (to allow dynamically choosing different branches) then this would help.

我评估过的当前资源:

推荐答案

REST API的主体部分应类似于:

The body part for the REST API should look like:

{
  "definition": {
    "id": 28
  },
  "sourceBranch": "$/xxxx/xxxx",
  "SourceVersion": "Cxxxx",
}

然后您可以指定sourceBranch和SourceVersion.

Then you can specify the sourceBranch and SourceVersion.

================================================ ===================

===================================================================

一个例子:

$Build_Definition_ID = '28'
$TFSInstanceURL = 'http://tfsservername:port/tfs'
$ProjectCollection = 'DefaultCollection'
$TeamProject = 'TestCase'
$Changeset = "C139"
$sourceBranch = "$/TestCase/TestCaseProject-branch"

$body = @"
   {
       "definition": {
           "id": "$Build_Definition_ID"
       },
       "sourceBranch": "$sourceBranch",
       "SourceVersion": "$Changeset",
   }
"@

这篇关于如何正确传递变量& TFS 2015中API 2.0 VNext Build的原始版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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