user62958
user62958

Reputation: 4929

Can I set an environment variable with the SVN revision number of a project?

I am trying to get the revision number of a project and save it into a variable. I know I can get the revision number by svnversion command but I'm not sure how I can store it. I am using regular windows command prompt. Basically I'm trying to do something like : set svnVersion= %svnversion% but I'm not sure how??

Upvotes: 4

Views: 5878

Answers (7)

s3v1
s3v1

Reputation: 2933

Here is an alternative that uses a pipe to findstr to get a single line:

FOR /F "tokens=2" %%G IN ('svn info ^| findstr /B Revision:') DO SET SVN_REVISION=%%G
echo SVN_REVISION: %SVN_REVISION%

FOR /F "tokens=2" %%G IN ('svn info ^| findstr /B URL:') DO SET SVN_URL=%%G
echo SVN_URL: %SVN_URL%

Upvotes: 0

BryanH
BryanH

Reputation: 6062

In bash (via Cygwin):

svn info | grep -i "Revision" | cut -d ' ' -f 2

You can then use that in a bash shell script to store the value in a variable.

Upvotes: 2

StocksR
StocksR

Reputation: 993

If you need this from a remote repository (as in not checked out localy) you can do this

for /f "delims=: tokens=1,2" %%a in ('svn info %SVN_REPO_URL%') do (
  if "%%a"=="Revision" (
    set /a RELEASE_REVISION=%%b
  )
)

I use this in my release process to grab the revision number from a tag.

Upvotes: 3

f3lix
f3lix

Reputation: 29877

To set the output of variable to the output of svnversion in a batch file, you have to do this:

for /f "delims=" %%a in ('svnversion') do @set myvar=%%a

echo %myvar% 

Different approach: If you have TortoiseSVN you can also use SubWCRev.exe. See get the project revision number into my project? or Automatic SVN Revision Numbering in ASP.Net MVC

Upvotes: 7

Steven Robbins
Steven Robbins

Reputation: 26599

Something like:

svn version > ver.txt
set /p ver= < ver.txt
del ver.txt
echo %ver%

Upvotes: 1

Jedi Master Spooky
Jedi Master Spooky

Reputation: 5809

See if this help: Change Revision Number

Upvotes: 0

Ken Liu
Ken Liu

Reputation: 22914

The "svn info" subcommand will tell you the revision number in your working copy.

Upvotes: 1

Related Questions