简体   繁体   中英

Get SVN revision number to batch file variable

Want to get last changed revision from svn branch in batch file.

echo on
set svnUrl=%1
set releaseName=%2
set buildNumber=%3


for /f %%i in ('svn info  %svnUrl%/branches/%releaseName% -r HEAD ^| FINDSTR "^Last.Changed.Rev:"') do set revisionNumber=%%i
echo %revisionNumber%

But I'm getting word Last instead of Last Changed Rev: 10

In console for command

D:\svn info http://desktop-24i22vk:81/svn/Test/branches/TST-1 -r HEAD

I'm receiving console output:

Path: TST-1
URL: http://desktop-24i22vk:81/svn/Test/branches/TST-1
Relative URL: ^/branches/TST-1
Repository Root: http://desktop-24i22vk:81/svn/Test
Repository UUID: 57a8baac-304e-e54b-94b3-b7d049dce932
Revision: 17
Node Kind: directory
Last Changed Author: import
Last Changed Rev: 10
Last Changed Date: 2016-07-22 15:26:37 +0200 (pá, 22 čvc 2016)

I want to get last changed revision number, here it's 10. I was thinking to store whole line text Last Changed Rev: 10 to variable and then replace text to get only number. I would appreciate even other (windows batch) approaches how to get it. Thanks

The default behavior of FOR /F is to break each line into tokens, delimited by spaces and/or tabs, and return only the first token of each line. That explains why you are only getting "Last".

You could preserve the entire line by setting the delims option to nothing

for /f "delims=" %%i ...

But you don't want the entire line. You just want the last (4th) token. So ...

for /f "tokens=4" %%i ...

可以使用svn info -r HEAD --show-item revision来仅获取 Head rev 作为输出...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM