我需要将相同的字段更新为TFS中数百个工作项的相同值。是否有任何方法可以批量执行,而不是逐个手动更新?
答案 0 :(得分:42)
您可以在 Excel :
中执行此操作
完整文档: Managing work items in Excel(概述页面;内部有很多和很多链接)
You can bulk-edit in the web interface too
Windows命令行:
REM make Martin Woodward fix all my bugs
tfpt query /format:id "TeamProject\public\My Work Items" |
tfpt workitem /update @ /fields:"Assigned To=Martin"
<强> Powershell的强>:
# make Bill & Steve happy
$tfs = tfserver -path . -all
$items = $tfs.wit.Query("
SELECT id FROM workitems
WHERE [Created By] IN ('bill gates', 'steve ballmer')") |
% {
$_.Open()
$_.Fields["priority"].value = 1
$_
}
# note: this will be much faster than tfpt since it's only one server call
$tfs.wit.BatchSave($items)
答案 1 :(得分:0)
$secpasswd = ConvertTo-SecureString $TfsPasswd -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($TfsUserName, $secpasswd)
Connect-TfsTeamProjectCollection -Server $TfsServerUrl -Collection $TfsCollection -Credential $mycreds
#Get-TfsTeamProject
Connect-TfsTeamProject -Project $TfsProjectName
$workItems = Get-TfsWorkItem -Filter "[System.WorkItemType] = 'Bug' AND [System.AssignedTo] = '$TfsUserName'"
foreach ($workItem in $workItems)
{
$tpc = $workItem.Store.TeamProjectCollection
$id = $workItem.Id
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
$wi = $store.GetWorkItem($id)
$projectName = $wi.Project.Name
foreach($fldName in $Fields.Keys)
{
$wi.Fields[$fldName].Value = $Fields[$fldName]
}
$wi.Save()
}
您可以从how to batch update multiple work items in TFS by PowerShell
下载详细信息脚本