· batch-scripts dos command-line svn

Getting latest tagged revision in SVN from DOS/Batch script

The way we have setup the build on our continuous integration server, Team City is configured to create a new tag every time the functional tests past successful on that machine.

We then have a QA and Showcase build that we can run to deploy all the artifacts necessary to launch the application on that machine.

Originally I had just written the batch script to take in the tag of the build which the user could find by looking through repo-browser for the last tag created. This quickly became very tedious so I started looking for a way to get the latest tagged revision from the command line.

We thought it would be possible to get this information using svn info but it turned out that the information returned by svn info about revisions doesn’t necessarily refer to the latest created tag. We ended up using svn log and then parsing through that data. It’s a bit messy but it does the job (I name each tagged version of the code as 'build-{TeamCity-Build-Number}):

12~
</td>
FOR /F "Tokens=2" %%i in ('svn log /tags/path --limit=1 -v ^| find "build"') do set TMP=%%iFOR /F "Tokens=2 delims=/" %%i in ('echo %TMP%') do SET TAG=%%i~
</td>
</tr>
</tbody></table>
The for loop uses a space as its default delimiter so that’s what the 'delims=/' is doing on the second line, the 'Tokens=2' allows us to get the second token after the string is split and the '^' in the first command is being used to escape the pipe.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket