我试图使用Batch脚本执行构建,我写了一个但是收到了这个错误:
请定义构建定义名称。 tfsbuild start / collection:https://tfs.prod.dcx.int.bell.ca/tfs/bellca/Consumer/builds/All Definitions / {Release)/ {Project-name} / {Build definition name}
我该如何解决这个问题?
答案 0 :(得分:1)
tfsbuild
命令行工具仅适用于XAML构建。对于现代版本,您需要使用REST API的REST API或C#包装器。
文档有很好的例子,但基本上是POST https://{instance}/DefaultCollection/{project}/_apis/build/builds?api-version={version}
有适当的身体:
{
"definition": {
"id": 25
},
"sourceBranch": "refs/heads/master",
"parameters": "{\"system.debug\":\"true\",\"BuildConfiguration\":\"debug\",\"BuildPlatform\":\"x64\"}"
}
答案 1 :(得分:1)
是的,正如Daniel所说,您需要使用REST API,请参阅Queue-a-build。
您可以简单地使用PowserShell脚本下面对构建进行排队(只需相应地替换params):
Param(
[string]$collectionurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "ProjectName",
[string]$keepForever = "true",
[string]$BuildDefinitionId = "34",
[string]$user = "username",
[string]$token = "password"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
function CreateJsonBody
{
$value = @"
{
"definition": {
"id": $BuildDefinitionId
},
"parameters": "{\"system.debug\":\"true\",\"BuildConfiguration\":\"debug\",\"BuildPlatform\":\"x64\"}"
}
"@
return $value
}
$json = CreateJsonBody
$uri = "$($collectionurl)/$($projectName)/_apis/build/builds?api-version=2.0"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}