使用.NET客户端库针对VSTS/TFS检索生成定义的任务列表 [英] Retrieve the list of Tasks for Build Definition using .NET client libraries for VSTS/TFS
问题描述
I'm using the .NET client libraries for VSTS/TFS (https://docs.microsoft.com/en-us/vsts/integrate/concepts/dotnet-client-libraries?view=vsts) to retrieve a list of tasks for all Build Definitions for all Team Projects. I'm using the v16.139.0-preview version of the NuGet package Microsoft.TeamFoundation.ExtendedClient (I need to because I need to retrieve Release Definition workflow as well for which you need Microsoft.VisualStudio.Services.Release.Client which has a dependency requirement for the ExtendedClient). The server (on-prem) is a TFS 2017.2. In no way I'm able to retrieve the tasks/phases/process. This is my code:
VssConnection connection = new VssConnection(new Uri("http://tfsserver:8080/tfs/defaultcollection"), new VssClientCredentials());
ProjectHttpClient projectClient = connection.GetClient<ProjectHttpClient>();
IEnumerable<TeamProjectReference> projects = projectClient.GetProjects().Result;
BuildHttpClient buildClient = connection.GetClient<BuildHttpClient>();
foreach (var project in projects)
{
IPagedList<BuildDefinition> buildDefinitions = buildClient.GetFullDefinitionsAsync2(project: project.Name, name: null).Result;
foreach (BuildDefinition buildDefinition in buildDefinitions)
{
// get the tasks
}
}
- 我尝试使用buildClient.GetDefinitionAsync重新获取构建定义,而没有其他影响
- "Steps"属性(将不建议使用)始终为空
- "Process"属性为空
- 没有可用的"phases"属性(在构建定义"中查看具有多个阶段的选项似乎是合乎逻辑的
- 有一个可用于BuildDefinitionStep的合同:有人对如何解决这个问题有想法吗?
Does anyone have an idea on how to solve this?
推荐答案
在@Andy的帮助下,我得以解决了该问题.我使用了Fiddler调用REST Api( http://server:8080/tfs/DefaultCollection/MyProject/_apis/build/definitions/1 ),然后读取JSON响应.我发现"build"属性包含任务的集合.我修复了@Andy提供的PowerShell脚本:
With the help of @Andy I was able to solve the problem. I used Fiddler call the REST Api (http://server:8080/tfs/DefaultCollection/MyProject/_apis/build/definitions/1) and read the JSON response. I discovered that the "build" property contains the collection of tasks. I fixed the PowerShell script provided by @Andy:
Param( [string]$baseurl = "http://server:8080/tfs/DefaultCollection", [string]$projectName = "MyProject", [string]$buildDefinitionID = "530", [string]$user = "domain\user", [string]$token = "PersonalAccessToken" ) # Base64-encodes the Personal Access Token (PAT) appropriately $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token))) $uri = "$baseurl/$($projectName)/_apis/build/definitions/$buildDefinitionID" Write-Host $uri $result = (Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}) foreach ($task in $result.build) { Write-Host $task.displayName }
这篇关于使用.NET客户端库针对VSTS/TFS检索生成定义的任务列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!