如何批量更新TFS中的多个工作项

时间:2009-07-31 03:36:34

标签: api tfs powershell bug-tracking

我需要将相同的字段更新为TFS中数百个工作项的相同值。是否有任何方法可以批量执行,而不是逐个手动更新?

2 个答案:

答案 0 :(得分:42)

您可以在 Excel

中执行此操作
  1. 通过以下方式在Excel中打开工作项:
    • 右键单击团队资源管理器中的查询 - >在Excel中打开
    • 在WIT结果窗格中多选一些工作项,然后右键单击 - >在Excel中打开
    • 加载Excel,使用Team - >导入以加载预定义查询
    • 打开已绑定到TFS的* .xls文件
  2. 进行批量修改
  3. 单击“团队”功能区上的“发布”按钮
  4. enter image description here

    完整文档: 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

下载详细信息脚本