我正在使用Microsoft.TeamFoundationServer.Client Nuget package来获取与某些构建相关的工作项列表。为此,我使用以下代码:
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using Microsoft.TeamFoundation.Build.WebApi;
public async Task<IEnumerable<ResourceRef>> GetBuildWorkItems(string vstsUrl, string teamProjectName, int buildId, string pat)
{
VssConnection connection = new VssConnection(new Uri(vstsUrl), new VssBasicCredential(string.Empty, pat));
using (var buildClient = connection.GetClient<BuildHttpClient>())
{
var workItems = await buildClient.GetBuildWorkItemsRefsAsync(teamProjectName, buildId);
return workItems;
}
}
除了工作项目是由具有涉众访问权限级别的用户创建的以外,此方法都很好。 GetBuildWorkItemsRefsAsync
方法不会特别返回这些工作项。
这是设计使然吗?我可以在VSTS管理员设置中为利益相关者用户配置一些东西,以免发生这种情况吗?
为澄清起见,我在团队项目中使用TFVC而不是Git。我不知道这是否与这个问题有关。
答案 0 :(得分:1)
尝试了GetBuildWorkItemsRefsAsync
方法,但没有发现问题。
但是,您可以简单地使用REST API来获取与特定内部版本关联的工作项列表:
GET https://{accountName}.visualstudio.com/{project}/_apis/build/builds/{buildId}/workitems?api-version=4.1
有关详细信息,请参见Builds - Get Build Work Items Refs。
PowerShell例如:
Param(
[string]$collectionurl = "https://{account}.visualstudio.com",
[string]$project = "ProjectName",
[string]$BuildID = "283",
[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)))
$WITbaseUrl = "$collectionurl/$project/_apis/build/builds/$($BuildID)/workitems"
#Response
$WITresponse = (Invoke-RestMethod -Uri $WITbaseUrl -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}).value
$WITrequests = @()
foreach($WITrequest in $WITresponse){
$customObject = new-object PSObject -property @{
"WorkitemID" = $WITrequest.id
"WorkitemURL" = $WITrequest.url
}
$WITrequests += $customObject
}
$WITrequests | Select `
WorkitemID,
WorkitemURL