如何正确地将变量和源版本传递给 API 2.0 VNext Build in TFS 2015
How to correctly pass variables & source version to API 2.0 VNext Build in TFS 2015
我很难找到将定义的变量和构建定义参数传递给新[=35=的正确方法] 2.0 使用 TFS 2015 构建引擎。我正在使用 TFS 2015 Update 3 on-premise。
我用 powershell 触发了 POST,如下所示:
$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)
- 传入自定义变量值
另外:
如果您知道传递参数的正确方法,例如要从源映射的文件夹(以允许动态选择不同的分支),那么这会有所帮助。
我评估过的当前资源:
- Visual Studio Docs > Api > Build > Builds
- 邮递员 - GET - 定义详细信息 - 审核响应以提交可能正确的结构
REST API 的正文部分应该如下所示:
{
"definition": {
"id": 28
},
"sourceBranch": "$/xxxx/xxxx",
"SourceVersion": "Cxxxx",
}
然后你可以指定sourceBranch和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",
}
"@
我很难找到将定义的变量和构建定义参数传递给新[=35=的正确方法] 2.0 使用 TFS 2015 构建引擎。我正在使用 TFS 2015 Update 3 on-premise。
我用 powershell 触发了 POST,如下所示:
$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) - 传入自定义变量值
另外: 如果您知道传递参数的正确方法,例如要从源映射的文件夹(以允许动态选择不同的分支),那么这会有所帮助。
我评估过的当前资源:
- Visual Studio Docs > Api > Build > Builds
- 邮递员 - GET - 定义详细信息 - 审核响应以提交可能正确的结构
REST API 的正文部分应该如下所示:
{
"definition": {
"id": 28
},
"sourceBranch": "$/xxxx/xxxx",
"SourceVersion": "Cxxxx",
}
然后你可以指定sourceBranch和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",
}
"@