如何从脚本添加自定义“构建摘要”部分?

时间:2015-12-15 16:47:05

标签: tfs tfsbuild tfs2013

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

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

1 个答案:

答案 0 :(得分:0)

我通过运行活动并查看它添加到构建信息中的内容来弄明白。

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