TFS 2017 Build Notifications do not include “Associated Changesets” area

℡╲_俬逩灬. 提交于 2019-12-10 23:09:04

问题


We recently upgraded from TFS 2010 to TFS 2017. We have build notifications set up for certain projects that send an email whether a build succeeds or fails with details of the build. Previously this email included a list of any unit tests that failed as well as a list of associated changesets. However, after the upgrade to TFS 2017 neither of these are included in the build notification emails. As far as I'm aware we didn't do any modification to the alert templates for TFS 2010 to get the missing information into the emails. Is there any way to get the list of failing unit tests and associated changesets on the TFS 2017 build notification emails?


回答1:


I have a partial solution. It doesn't look like work items are available, but changesets are, just with some different names.

First I opened up %programfiles%\Microsoft Team Foundation Server 1X.0\Application Tier\TFSJobAgent\Transforms\1033\BuildCompletedEvent.xsl and replaced its contents with something to just dump the source xml back. Keep the old contents of this file around, as you'll need to edit it later.

<xsl:template match="/">
    <xsl:copy-of select="."/>
</xsl:template>

Check in some code and start a build that will pick it up, then look at your build notification email to see the source XML that's feeding that XSL template. You'll see that AssociatedChangeset has become AssociatedCommit along with a few other little changes. I'm amazed that Microsoft would change the model's schema and ignore the templates reading that model.

Replace all the original content in BuildCompletedEvent.xsl, then inside the tb:BuildCompletedEvent template, find this:

<xsl:if test="count(tb:Build/tb:Information/tb:BuildInformationNode[@Type = 'AssociatedChangeset']) > 0">
  <h2 style="font-size: 12pt; margin-bottom: 0em;">
    <span _locID="AssociatedChangesets">Associated Changesets</span>
  </h2>
  <div style="margin-left:1em">
    <table style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 10pt;">
      <xsl:apply-templates select="tb:Build/tb:Information/tb:BuildInformationNode[@Type = 'AssociatedChangeset']">
        <xsl:sort select="tb:Fields/tb:InformationField[@Name = 'ChangesetId']/@Value"/>
      </xsl:apply-templates>
    </table>
  </div>
</xsl:if>

And put this before it:

<xsl:if test="count(tb:Build/tb:Information/tb:BuildInformationNode[@Type = 'AssociatedCommit']) > 0">
  <h2 style="font-size: 12pt; margin-bottom: 0em;">
    <span _locID="AssociatedCommits">Associated Commits</span>
  </h2>
  <div style="margin-left:1em">
    <table style="font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-size: 10pt;">
      <xsl:apply-templates select="tb:Build/tb:Information/tb:BuildInformationNode[@Type = 'AssociatedCommit']">
        <xsl:sort select="tb:Fields/tb:InformationField[@Name = 'CommitId']/@Value"/>
      </xsl:apply-templates>
    </table>
  </div>
</xsl:if>

And the actual changeset template, find this:

<xsl:template match="tb:BuildInformationNode[@Type = 'AssociatedChangeset']">
  <tr>
    <td style="padding-right:2em">
      <strong>
        <xsl:value-of select="tb:Fields/tb:InformationField[@Name = 'CheckedInBy']/@Value"/>.
      </strong>
      <xsl:call-template name="linefeed2br">
        <xsl:with-param name="StringToTransform" select="tb:Fields/tb:InformationField[@Name = 'Comment']/@Value"/>
      </xsl:call-template>
      - 
      <a>
        <xsl:attribute name="href">
          <xsl:value-of select="tb:Fields/tb:InformationField[@Name = 'WebAccessUri']/@Value"/>
        </xsl:attribute>
        Changeset <xsl:value-of select="tb:Fields/tb:InformationField[@Name = 'ChangesetId']/@Value"/>
      </a>
    </td>
  </tr>
</xsl:template>

And put this before it:

<xsl:template match="tb:BuildInformationNode[@Type = 'AssociatedCommit']">
  <tr>
    <td style="padding-right:2em">
      <strong>
        <xsl:value-of select="tb:Fields/tb:InformationField[@Name = 'Author']/@Value"/>.
      </strong>
      <xsl:call-template name="linefeed2br">
        <xsl:with-param name="StringToTransform" select="tb:Fields/tb:InformationField[@Name = 'Comment']/@Value"/>
      </xsl:call-template>
      - 
      <a>
      <xsl:variable name="href" select="tb:Fields/tb:InformationField[@Name = 'Uri']/@Value"/>
        <xsl:variable name="fragment" select="'/_apis/tfvc/changesets/'"/>
        <xsl:attribute name="href">
          <!--<xsl:value-of select="replace(tb:Fields/tb:InformationField[@Name = 'Uri']/@Value, '/_apis/tfvc/changesets/', '/_versionControl/changeset/')"/>-->
          <xsl:value-of select="substring-before($href,$fragment)"/>
          <xsl:value-of select="'/_versionControl/changeset/'"/>
          <xsl:value-of select="substring-after($href,$fragment)"/>
        </xsl:attribute>
        Changeset <xsl:value-of select="tb:Fields/tb:InformationField[@Name = 'CommitId']/@Value"/>
      </a>
    </td>
  </tr>
</xsl:template>

Note that the Uri in the XML returns JSON for API integration, hence the string replacement to make it a link to the web UI. I had issues getting the replace() function working, hence the substrings.

http://tfs:8080/tfs/DefaultCollection/_apis/tfvc/changesets/10516
http://tfs:8080/tfs/DefaultCollection/_versionControl/changeset/10516

I added to the existing template rather than change the broken references. I'm holding out some hope that maybe if a TFS upgrade changes the model names back to the old ones, then the template will still match them and pull them up without me having to edit anything.

Also note that after changing, something needs to be done to get TFS to see the new template. When doing this, I was restarting the TFS services: https://www.visualstudio.com/en-us/docs/setup-admin/tfs/command-line/tfsservicecontrol-cmd

I haven't pulled the source XML with failed unit tests, but if someone else does and it shows details of which tests failed, please share your updated XSL.




回答2:


This has been a uservoice for the new vNext build. The changeset data and the associated work items don't seem to be exposed to default BuildCompletedEvent.xsl

Using TFS 2015 Build (Build vNext) email alerts don't show associated check-ins

https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/9754887-using-tfs-2015-build-build-vnext-email-alerts-do

For now you may have to customize your email alert Drive:\%programfiles%\Microsoft Team Foundation Server 1X.0\Application Tier\TFSJobAgent\Transforms\1033 . More details please refer Customize the format for TFS email alerts



来源:https://stackoverflow.com/questions/42988376/tfs-2017-build-notifications-do-not-include-associated-changesets-area

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