【问题标题】:How can I add a custom Build Summary section from a script?如何从脚本中添加自定义构建摘要部分?
【发布时间】:2016-03-21 13:48:12
【问题描述】:

我有一个运行 PowerShell 脚本(将包推送到 NuGet)的 TFS 2013 XAML 构建过程模板。

用于 XAML 构建的构建活动 WriteCustomSummaryInformation was added in TFS2012。我想从我的脚本中以某种方式使用相同的活动或实现相同的功能(以便我可以显示发布了哪些包)。我该怎么做?

【问题讨论】:

    标签: tfs tfsbuild


    【解决方案1】:

    我通过运行活动并查看它添加到构建信息中的内容来解决这个问题。

    Function New-CustomSummaryInformation($Build, $Message, $SectionHeader, $SectionName, $SectionPriority = 0)
    {
        $CustomSummaryInformationType = 'CustomSummaryInformation'
    
        $root = $Build.Information.Nodes | ? { $_.Type -eq $CustomSummaryInformationType } | select -First 1
        if (!$root)
        {
            $root = $Build.Information.CreateNode()
            $root.Type = 'CustomSummaryInformation'
        }
    
        $node = $root.Children.CreateNode()
        $node.Type = 'CustomSummaryInformation'
    
        $node.Fields['Message'] = $Message
        $node.Fields['SectionHeader'] = $SectionHeader
        $node.Fields['SectionName'] = $SectionKeyName
        $node.Fields['SectionPriority'] = $SectionPriority
    }
    
    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')
    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.VersionControl.Client')
    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Build.Client')
    
    $workspaceInfo = [Microsoft.TeamFoundation.VersionControl.Client.Workstation]::Current.GetLocalWorkspaceInfo($env:TF_BUILD_SOURCESDIRECTORY )
    $tpc = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection $workspaceInfo.ServerUri
    $vcs = $tpc.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
    $buildServer = $tpc.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
    
    $buildDef = $buildServer.GetBuildDefinition("MyProject", "MyBuildDefn")   
    $build = $buildServer.GetBuild($def.LastBuildUri)
    New-CustomSummaryInformation $build -Message "This is a test message" -SectionHeader "This is the header displayed" -SectionName "ThisIsAnInternalKey"
    
    $build.Information.Save()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      相关资源
      最近更新 更多