1

I am using a TeamCity Trigger to build everything once there is a commit to svn on the branch. Once successful it send an email notification which includes the VCS changes that caused this build to be triggered. From a TeamCity perspective this works fine.

There are now multiple members on the team who do not have permissions to TC and cannot set up notifications. With this I have decided to use NAnt's <mail> to send this notification along with the Build number using "${environment::get-variable('BUILD_NUMBER')}" . This works fine within teamcity. However, I also need to send the Changes that triggered that build in the message of that email notification.

Currently TeamCity formats the VSC changes to the email like this:

     Changes included (1 change).
     Change 10433 by John Doe (4 files): Issue#245 - Issue description

I am looking to generate the same changes from TeamCity using NAnt. TeamCity defines this format in the common.flt file using the build_changes bean.

**Changes included (${changesLink})
  Change ${mod.displayVersion} ${pers} by ${mod.userName} (${modLink}):
          <i>${description?trim}</i>**

How can I use this within my NAnt messages? Since TeamCity already know what svn change triggered the build, it will be better to get this change and add it to my NANT messages for the email. Is there is simple way to do this?

Geddon
  • 1,266
  • 1
  • 11
  • 31

1 Answers1

4

I've never used NAnt but can offer two other solutions...

1) Create an email mailing list and add all the people that require it to the list.

Then create a teamcity user for with its email to to the mailing list and setup the required notifications to that user.

Restrictions to this is you have to create a user per mailing list which can eat up the licenses.

2) You can use the TeamCity REST API to get that information from the running build. Use %teamcity.build.id% which will return the build id and perform the following lookup:

/httpAuth/app/rest/changes?build=id:%teamcity.build.id%

Which will return all the changes for the build which will like:

<changes count="3">
   <change href="/httpAuth/app/rest/changes/id:217404" id="217404" version="b6b97a0d7789d97df6df908ab582ebb723235f43" webLink="http://teamcity.my-domain.com/viewModification.html?modId=217404&personal=false"/>
   <change href="/httpAuth/app/rest/changes/id:217403" id="217403" version="064ecef5552ec2fb7875d7c26fe54cdf94b67bec" webLink="http://teamcity.my-domain.com/viewModification.html?modId=217403&personal=false"/>
   <change href="/httpAuth/app/rest/changes/id:217402" id="217402" version="9bc3a34c952059bbfc7bebeb79ba5a3c894ef555" webLink="http://teamcity.my-domain.com/viewModification.html?modId=217402&personal=false"/>
</changes>

Then loop through the href url results for each of the <change> elements. Which return something like:

<change date="20130918T133404-0600" username="welsh" href="/httpAuth/app/rest/changes/id:217397" id="217397" version="51e925e354a83deccde881b30a76974b2ff745f4" webLink="http://teamcity.my-domain.com/viewModification.html?modId=217397&personal=false">
  <comment>
    My comments are here
  </comment>
  <files>
    <file before-revision="90acd4da1972814094c22e3020c5073521a7b640@141323126c0" after-revision="51e925e354a83deccde881b30a76974b2ff745f4@1413290abe0" file="grails-app/views/layouts/global.gsp" relative-file="grails-app/views/layouts/global.gsp"/>
  </files>
  <user href="/httpAuth/app/rest/users/id:1" id="1" name="Welsh" username="welsh"/>
</change>

And use that to build your email to who you email to whoever which is more work to create initially but more freedom on who you email without eating up licenses.

Welsh
  • 5,138
  • 3
  • 29
  • 43
  • Thanks. I never used TeamCity's RestAPI before. Based on your solution I was able to get the teamcity.build.id and since this is in xml format I decided to do an within nant to get the count and the svn revision. If the count is greater than 0 then I generate an svn log with the changes which can now be sent in the messages of the email. Works Perfectly now. Thanks again. – Geddon Oct 24 '13 at 19:31
  • Hey Welsh.I know you said you never used NAnt, but this might be a TeamCity thing.. At the Build Step TC config setting, if I use `/httpAuth/app/rest/changes?build=id:%teamcity.build.id%` while pasting my **Build file content**, it returns the `build.id` fine, but if I use it in the build Nant file **TeamCity** does not Return the `build.id`. I prefer to call the Nant file by specifying the path rather than pasting it in **TeamCity**. Do you know why this is? – Geddon Oct 25 '13 at 14:29
  • TeamCity replaces `%teamcity.build.id%` with the actual `build.id` if it has visibility into it. So if you just have that text in your NAnt build file, TC doesn't know to replace it since the NAnt process gets forked off. However, if you are using the TC Integrated NAnt runner, you should be able to use the option `Command line parameters:` and pass in `-D:arg.buildId=%teamcity.build.id%`. Then inside your NAnt script use `${arg.buildId}`. – Welsh Oct 25 '13 at 17:16
  • Ah. Got it, makes sense. I will use the argument for the build.id. Should work. many Thanks !!! – Geddon Oct 25 '13 at 17:43