需要获取Team项目集合或Team项目下的分支列表,这需要在某些txt或csv文件中编写。我正在使用TFS 2015。
是否有一些脚本可用?最好是Powershell脚本
先谢谢, 迪内希。
答案 0 :(得分:3)
REST API和Client API都可以满足您的需求。您也可以在Powershell脚本中使用它们。
使用Rest API - Get a branch
GET https://{instance}/DefaultCollection/_apis/tfvc/branches/{path}?api-version={version}[&includeChildren={bool}&includeParent={bool}&includeDeleted={bool}]
使用客户端API
在C#中使用Powershell
# Define parameters
$tfsCollectionUrl = New-Object System.URI("http://ditfs.cloudapp.net:8080/tfs/disample");
# Load Client Assembly
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.VersionControl.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Lab.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
[Reflection.Assembly]::Load(“Microsoft.TeamFoundation.Lab.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”);
# Connect to tfs
$tfsCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl);
$projectService = $tfsCollection.GetService([Microsoft.TeamFoundation.Server.ICommonStructureService]);
$versionControl = $tfsCollection.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]);
# Query all the projects and branches
$projects = $projectService.ListAllProjects();
$objallbranch = $versionControl.QueryRootBranchObjects("full")
foreach ($project in $projects)
{
Write-Host Finding environments for project $project.Name
foreach ($branchObject in $objallbranch)
{
if ($branchObject.Properties.RootItem.Item.ToUpper().Contains($project.Name.ToUpper()))
{
write-host $branchObject
}
}
}
来自GitHub的