July 28, 2010
Next steps - Getting started with Rational Team Concert and Microsoft Visual Studio.

If you have followed Introduction: demo “How to get started with Team Concert and Microsoft® Visual Studio® article on Jazz Team Wiki and watched the video here, you’ve probably got the RTC up and running, but still, some basic functionality remains to be implemented, namely:

  • Unit tests.
  • Automatic email notification on successful built (with Unit test reports).
  • Getting last change info (in email).

In this article, I’ll be writing about, how to implement these functionalities if you are using an older version of RTC, though with new RTC 3.0 M7a (Beta 1), support for build notification emails, and simpler configuration of VS based builds, including publishing NUnit and MSTest results already exists.Getting started with Unit tests, you’ll need basic knowledge of XSLT, Perl and XML. Let’s get started.

—>>[1.]  Open the build.bat file and paste this after devenv.exe is executed (I used /Rebuild Release, to enable Release mode) -

——————————————————————————-

del C:\demoblank\buildscript\results.xml

"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe” /testcontainer:C:\demoblank\build\Source\Project_Name.UnitTests\bin\Release\Project_Name.UnitTests.dll /resultsfile:C:\demoblank\buildscript\results.xml

“C:\demoblank\buildscript\msxsl.exe” C:\demoblank\buildscript\results.xml C:\demoblank\buildscript\MsTestReport2008.xsl -o C:\demoblank\buildscript\Report.html 

——————————————————————————————–

So, what does it mean? 

->First line deletes results.xml to ensure a clean and new Unit test results.xml file’s generation.

->Second line uses MSTest.exe to generate results.xml with the help of UnitTests project’s dll. 

->Third line uses msxsl.exe to generate HTML report of UnitTests with the help of MsTestReport2008.xsl and results.xml 

We’re done, now we will use this Report.html as an attachment in email. So, let’s get started with sending email functionality. 

—>>[2.] Open build.bat again and just after startPublish is executed, paste this-

——————————————————————————-

“C:\Program Files\IBM\TeamConcertBuild\buildsystem\buildengine\eclipse\jdk\bin\java” -cp “C:\Program Files\IBM\TeamConcertBuild\buildsystem\buildengine\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\lib\ant-launcher.jar” org.apache.tools.ant.launch.Launcher -f C:\demoblank\buildScript\jazzbuild.xml -lib “C:\Program Files\IBM\TeamConcertBuild\buildsystem\buildtoolkit” -DrepositoryAddress=%1 -DbuildResultUUID=%2 mailer

——————————————————————————————–

Then open jazzbuild.xml, and paste this after startPublish-

——————————————————————————-

<target name=“mailer”>

<property name=“report” value=“C:\demoblank\buildScript\Report.html”/>

<mail from=“BuildManager@company.com” messagemimetype=“text/html” charset=“ISO-8859-1” messagefile=“${report}” mailhost=“AMRMR2001.company.com” mailport=“25” tolist=“developer1@company.com,developer2@company.com” subject=“Build status” />                 

</target>

——————————————————————————————–

You’re ready to go! Email sent :) Next what? you would also want to see last changes in the email. RTC does not have current functionality inbuilt in the same, so we’ll have to use SCM Command line for the same, you might want to read a detailed tutorial on the same here. Ready? 

—>>[3.] So, well, I haven’t used a very clean way to do it, but it works, gives the implementation technique and can be improved, we just need to play a bit with Perl script, so, open the build.bat file again and paste the following after Report.html is created:

——————————————————————————-

“C:\Program Files\IBM\TeamConcert\scmtools\eclipse\scm.exe” –show-uuid y –show-alias n list snapshots -r https://10.186.165.143:9443/jazz/ -u BuildAdmin -P Password “Build WorkSpace” > “C:\demoblank\buildScript\Snapshotlist.txt”

cd “C:\demoblank\buildScript”

perl “C:\demoblank\buildscript\Snapshotperl.pl” > “C:\demoblank\buildscript\snapshot.bat”

call “C:\demoblank\buildscript\snapshot.bat” > “C:\demoblank\buildscript\change.txt”

perl “C:\demoblank\buildscript\Snapshotextract.pl” > “C:\demoblank\buildscript\change2.txt”

copy/Y “C:\demoblank\buildScript\change1.txt”+“C:\demoblank\buildScript\change2.txt”+“C:\demoblank\buildScript\change3.txt” “C:\demoblank\buildScript\ChangeReport.html”

——————————————————————————————–

The first line creates Snapshotlist.txt, which contains something like:

——————————————————————————-

(_mh9AYVm7Ed-7jddFtRqYuA) “Team Area build_20100507-1503” May 7, 2010 3:03 PM

(_IIuqE1m5Ed-7jddFtRqYuA) “Team Area build_20100507-1445” May 7, 2010 2:45 PM

——————————————————————————————–

to parse the same, we need Perl script (Snapshotperl.pl), which further outputs a command, saved in snapshot.bat. 

Source of Snapshotperl.pl is:

——————————————————————————-

#!/usr/bin/perl

open (FILE, ‘snapshotlist.txt’);

$i=0;

while (<FILE>) {

if($i<2)

chomp;

(@snapshotID) = split(“"”);

$snap[$i] = $snapshotID[1];

$i++;

}close (FILE);

print $snapshotcommand = “"C:\Program Files\IBM\TeamConcert\scmtools\eclipse\scm.exe" ”.“-u ”.“yes ”.“compare ”.“-r ”.“"https://10.186.165.143:9443/jazz/" ”.“-u ”.“BuildAdmin ”.“-P ”.“Password ”.“snapshot ”.“"$snap[0]"”.“ snapshot ”.“"$snap[1]"”; 

exit;

——————————————————————————————–

Now, the Snapshot.bat contains:

——————————————————————————-

“C:\Program Files\IBM\TeamConcert\scmtools\eclipse\scm.exe” -u yes compare -r “https://10.186.165.143:9443/jazz/” -u BuildAdmin -P Password snapshot “Area build_20100507-1503” snapshot “Area build_20100507-1445”

——————————————————————————————–

which when executed, gives this(pasted in change.txt):

——————————————————————————-

C:\blankdemo\buildScript>“C:\Program Files\IBM\TeamConcert\scmtools\eclipse\scm.exe” -u yes compare -r “https://10.186.165.143:9443/jazz/” -u BuildAdmin -P Password snapshot “Team Area build_20100507-1503” snapshot “Team Area build_20100507-1445" 

——————————————————————————————–

To extract, we further use another perl script( Snapshotextract.pl):

——————————————————————————-

#!/usr/bin/perl

open (FILE, 'change.txt’);

@lines = <FILE>;

close (FILE);

$i=2;

foreach (@lines) {

print $lines[$i];

$i++; }exit;

——————————————————————————————–

Which gives last change in change2.txt, and looks like this: 

——————————————————————————-

Outgoing Changes Component (1018) "SOURCE” (1020) developer1 192: Adding extra spaces in glossary conflicts with the Application Markup - Trimming terms in glossary 2010/02/03 Incoming Changes Component (1018) “SOURCE” (this can further be parsed to remove irrelevant content). 

——————————————————————————————–

The last line then merges all change files and adds to ChangeReport.html, which can be finally appended or iframed with Report.html. We’re done.

If anything remains unclear, shoot me an email at vaish.rajan @ Gmail dot com or post a comment below. Thanks.