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??
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
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.
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.
“svn info”子命令将告诉您工作副本中的修订号。
Something like:
svn version > ver.txt
set /p ver= < ver.txt
del ver.txt
echo %ver%
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%
查看是否有此帮助: 更改版本号
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.