TFS Build vNext rest api:请求队列构建
TFS Build vNext rest api: queue build requested for
我正在尝试使用 TFS Rest API 对来自 PowerShell 的新构建进行排队。我可以对新构建进行排队,但我想设置 requestedBy 属性。在 docs 中可以看到您可以传递其他参数。我找不到关于这些参数可以是什么的任何进一步文档。有谁知道这是否可以做到?
使用 tfsbuild.exe
(排队 XAML 构建)你可以像这样传递一个额外的参数:
&$tfsBuild.Exe start "url" project definition /requestedFor:"$buildRequestedFor" /queue
编辑
我已经能够让它工作了。请求正文如下所示:
$json = "{
""definition"": {
""id"" : 174
}
,""requestedFor"": {
""id"": ""6f4d7323-fa51-4cda-9eb4-7342b02ba087""
}
}" `
您只能使用 ID 属性。例如,使用 uniqueName 将失败。
这是完整的 PowerShell 代码:
$user = ""
$pass= ""
$uri = "http://Instance/DefaultCollection/Project/_apis/build/builds?api-version=2.0"
$json = "{
""definition"": {
""id"" : 174
}
,""requestedFor"": {
""id"": ""6f4d7323-fa51-4cda-9eb4-7342b02ba087""
}
}"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
Invoke-RestMethod -Uri $uri -Method Post -Credential $cred -ContentType "application/json" -Body $json
您应该能够使用 PowerShell queue 通过 Invoke-RestMethod
cmdlet 进行构建。这 link 可能会有所帮助。挑战在于 REST API 看起来还没有完整的文档,因此有些属性只能通过使用像 Fiddler 这样的工具才能找到。您也许可以将 body 更改为这样的内容,但我还没有尝试过。
$body = @"
{
"definition": {
"id": $Build_Definition_ID
},
"sourceVersion": {
"requestedBy": {name here}
}
}
"@
这是一个您应该能够修改的示例(缺少一些变量的声明,但这应该可以帮助您入门):
$body = @"
{
"definition": {
"id": $Build_Definition_ID
}
}
"@
$baseUri = $TFSInstanceURL+"/"+$ProjectCollection+"/"+$TeamProject+"/_apis/build"
$postUri = $baseUri+"/builds?api-version=2.0"
Write-Host $postUri
##Create a new PSCredential based on username/password
$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)
有关更多示例,请参阅此 link。
我已经能够让它工作了。请求正文如下所示:
$json = "{
""definition"": {
""id"" : 174
}
,""requestedFor"": {
""id"": ""6f4d7323-fa51-4cda-9eb4-7342b02ba087""
}
}"
您只能使用 ID 属性。例如,使用 uniqueName 将失败。
我正在尝试使用 TFS Rest API 对来自 PowerShell 的新构建进行排队。我可以对新构建进行排队,但我想设置 requestedBy 属性。在 docs 中可以看到您可以传递其他参数。我找不到关于这些参数可以是什么的任何进一步文档。有谁知道这是否可以做到?
使用 tfsbuild.exe
(排队 XAML 构建)你可以像这样传递一个额外的参数:
&$tfsBuild.Exe start "url" project definition /requestedFor:"$buildRequestedFor" /queue
编辑
我已经能够让它工作了。请求正文如下所示:
$json = "{
""definition"": {
""id"" : 174
}
,""requestedFor"": {
""id"": ""6f4d7323-fa51-4cda-9eb4-7342b02ba087""
}
}" `
您只能使用 ID 属性。例如,使用 uniqueName 将失败。
这是完整的 PowerShell 代码:
$user = ""
$pass= ""
$uri = "http://Instance/DefaultCollection/Project/_apis/build/builds?api-version=2.0"
$json = "{
""definition"": {
""id"" : 174
}
,""requestedFor"": {
""id"": ""6f4d7323-fa51-4cda-9eb4-7342b02ba087""
}
}"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
Invoke-RestMethod -Uri $uri -Method Post -Credential $cred -ContentType "application/json" -Body $json
您应该能够使用 PowerShell queue 通过 Invoke-RestMethod
cmdlet 进行构建。这 link 可能会有所帮助。挑战在于 REST API 看起来还没有完整的文档,因此有些属性只能通过使用像 Fiddler 这样的工具才能找到。您也许可以将 body 更改为这样的内容,但我还没有尝试过。
$body = @"
{
"definition": {
"id": $Build_Definition_ID
},
"sourceVersion": {
"requestedBy": {name here}
}
}
"@
这是一个您应该能够修改的示例(缺少一些变量的声明,但这应该可以帮助您入门):
$body = @"
{
"definition": {
"id": $Build_Definition_ID
}
}
"@
$baseUri = $TFSInstanceURL+"/"+$ProjectCollection+"/"+$TeamProject+"/_apis/build"
$postUri = $baseUri+"/builds?api-version=2.0"
Write-Host $postUri
##Create a new PSCredential based on username/password
$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)
有关更多示例,请参阅此 link。
我已经能够让它工作了。请求正文如下所示:
$json = "{
""definition"": {
""id"" : 174
}
,""requestedFor"": {
""id"": ""6f4d7323-fa51-4cda-9eb4-7342b02ba087""
}
}"
您只能使用 ID 属性。例如,使用 uniqueName 将失败。