[英]Get SVN revision number to batch file variable
Want to get last changed revision from svn branch in batch file.想要从批处理文件中的 svn 分支获取最后更改的修订版。
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但是我得到的是 Last 而不是 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.我想获得最后更改的修订号,这里是 10。我想将整行文本 Last Changed Rev: 10 存储到变量,然后替换文本以仅获取数字。 I would appreciate even other (windows batch) approaches how to get it.
我什至会欣赏其他(Windows 批处理)方法如何获得它。 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. FOR /F 的默认行为是将每一行分成标记,以空格和/或制表符分隔,并仅返回每行的第一个标记。 That explains why you are only getting "Last".
这解释了为什么你只得到“最后”。
You could preserve the entire line by setting the delims option to nothing您可以通过将 delims 选项设置为空来保留整行
for /f "delims=" %%i ...
But you don't want the entire line.但你不想要整条线。 You just want the last (4th) token.
您只需要最后一个(第 4 个)令牌。 So ...
所以...
for /f "tokens=4" %%i ...
可以使用svn info -r HEAD --show-item revision
来仅获取 Head rev 作为输出...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.