вторник, 28 июня 2011 г.

Generate changelog from Bamboo with Mercurial


We use bamboo(v.3) for supports continuum integration in our project and mercurial as control version system. We wrote some core functions for the project and now should test it. Testers want to see what's new we do in new build. For this reason developers should wrote changelog for new build. But we are lazy developers and don't want to do this :) Unfortunately, bamboo can not generate changelog for mercurial. For make this, I added new stage to bamboo and create one script task in it.

Bamboo has list of global variables that you can use in scripts. Full list of these variables you can see here. I interested two of these variables:
bamboo.repository.revision.number - The revision number
repository.previous.revision.number - The previous revision number (might not exist if for example is initial build)
Now, I simple need to get changes between these revisions. Mercurial has powerful command:
hg log. It supports different templates. I use next command to get log:
hg log -r ${bamboo.repository.previous.revision.number}:${bamboo.repository.revision.number} --template "{rev}:{author} - {desc}\n" -P ${bamboo.repository.previous.revision.number}
I use flag -P to exclude revision from previous build.

Our build server works under Windows Server 2008 and I wrote batch in script task to generate changelog.

IF EXIST C:\changelog.txt (
  COPY C:\changelog.txt C:\changelog.txt.tmp

ECHO Build ${bamboo.buildNumber} - ${bamboo.buildTimeStamp} > C:\changelog.txt

IF ${bamboo.repository.previous.revision.number}==${bamboo.repository.revision.number} (
   echo [No changes] >> C:\changelog.txt
) ELSE ( 
   hg log -r ${bamboo.repository.previous.revision.number}:${bamboo.repository.revision.number} --template "{rev}:{author} - {desc}\n" -P ${bamboo.repository.previous.revision.number} >> C:\changelog.txt

ECHO ++++++++++++++++++++++++++ >> C:\changelog.txt
ECHO. >> C:\changelog.txt

IF EXIST C:\changelog.txt.tmp (
  TYPE C:\changelog.txt.tmp >> C:\changelog.txt
  DEL C:\changelog.txt.tmp

Комментариев нет:

Most popular