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

I am trying to get the revision number of a project and store it in a variable. I know that I can get the version number with the svnversion command, but I'm not sure how I can save it. I use the standard Windows command line. Basically I'm trying to do something like: set svnVersion =% svnversion%, but I'm not sure how?

+4
source share
7 answers

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

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

A different approach: if you have TortoiseSVN, you can also use SubWCRev.exe . See getting the project version number in my project? or Automatic SVN versioning in ASP.Net MVC

+7
source

If you need this from a remote repository (as in untested 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 version number from the tag.

+3
source

In bash (via Cygwin):

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

Then you can use this in a bash shell script to store the value in a variable.

+2
source

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

+1
source

Sort of:

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

See if this help: Change version number

0
source

Here is an alternative that uses pipe for 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% 
0
source

All Articles