Jun 062014
 

In my current ant-script I need to get the SVN revision to insert that info into the deployment-package.

There are three commands available.

svn info is the first one:

D:\Projekte\workspace\myCode >svn info
Pfad: .
URL: https://svn.xxx.xx/abc/def/
Basis des Projektarchivs: https://svn.svn.xxx.xx/abc/def/
UUID des Projektarchivs: hidden
Revision: 12955
Knotentyp: Verzeichnis
Plan: normal
Letzter Autor: pbo
Letzte geänderte Rev: 12859
Letztes Änderungsdatum: 2014-05-21 10:10:14 +0200 (Mi, 21. Mai 2014)

The Revision is the current Revision of the Repository (that means, that if you checkin some changes now, you will get the Revsion 12955+1). The „Letzte geänderte Rev“ (last changed revision) ist the one which was assigned on the last commit/checkin. This is the revision of code that is checked in on the repository. This format is diffiult to handle in ant, that’s the reason why I present another solution:

svnversion

svnversion without any parameter will display the revsion of the repositry:

D:\Projekte\workspace\myCode>svnversion
12955M

„M“ means, that the local code has changed (modified). If you need the latest commited revision, you can append the parameter „-c“:

D:\Projekte\workspace\myCode>svnversion -c
11789:12859M

The firs number is the revision that was assigned during first checkin of this project / path. The second number is the revision of the latest commit. There is also a third solution:

svn log

With the svn command with the log parameter you are able to see the commit-messages. With some parameters you can display only the latest commit, including revsion number, date and author:

D:\Projekte\workspace\myCode>svn log -r COMMITTED -q
------------------------------------------------------------------------
12859| pbo | 2014-05-21 10:10:14 +0200 (Mi, 21. Mai 2014)
------------------------------------------------------------------------

How to use this in ant:

<target name="svnversion">
	<exec executable="svnversion" outputproperty="svnversion" />
	<echo message="SVN Version: ${svnversion}" />
</target>

Results in:

Buildfile: D:\Projekte\workspace\myCode\svn.xml
svnversion:
     [echo] SVN Version: 129555M
BUILD SUCCESSFUL
Total time: 834 milliseconds

 

<target name="svnLog">
	<exec executable="svn" outputproperty="lastCommittedRevision">
		<arg value="log" />
		<arg value="-r" />
		<arg value="COMMITTED" />
		<arg value="-q" />
	</exec>
	<echo message="lastCommittedRevision = " />
	<echo message="${lastCommittedRevision}" />
</target>

Results in:

Buildfile: D:\Projekte\workspace\myCode\svn.xml
svnLog:
     [echo] lastCommittedRevision = 
     [echo] ------------------------------------------------------------------------
     [echo] r12859 | pbo | 2014-05-21 10:10:14 +0200 (Mi, 21. Mai 2014)
     [echo] ------------------------------------------------------------------------
BUILD SUCCESSFUL
Total time: 1 second

 

Sorry, the comment form is closed at this time.