How to batch update multiple workitems in TFS

做~自己de王妃 提交于 2020-08-01 05:29:06

问题


I need to update same field to same value for hundreds of workitems in TFS. Is there any way to do it in a batch instead of updating them manually one by one?


回答1:


You can do this in Excel:

  1. Open the work items in Excel, via:
    • right click a query in Team Explorer -> open in Excel
    • multi-select some work items in a WIT result pane, then right click -> open in Excel
    • load Excel, use Team -> Import to load a predefined query
    • open a *.xls file that is already bound to TFS
  2. Make your bulk edits
  3. Click the Publish button on the Team ribbon

enter image description here

Full documentation: Managing work items in Excel (overview page; lots & lots of links inside)

You can bulk-edit in the web interface too

Windows command line:

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)   



回答2:


$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()
}

You can download detail script from how to batch update multiple work items in TFS by PowerShell



来源:https://stackoverflow.com/questions/1210571/how-to-batch-update-multiple-workitems-in-tfs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!