Reputation: 597
I am executing batch file from apache ant build.xml, running from Jenkins CI job ( Win 7 x64 Ent SP1 ).
batch file:
@Echo Off
svn info | findstr /C:"Relative URL:" > temp1.txt
set /p str=<temp1.txt
echo !str! @ > temp1.txt
svn info | findstr /C:"Revision:" > temp2.txt
copy *.txt temp3.txt
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (temp3.txt) do (
set s=!s!%%a
)
echo !s! >> BrandingText.PROPERTIES
The results are as follows:
BrandingText.PROPERTIES:
@ Revision: 133708
temp3.txt:
!str! @
Revision: 133708
temp2.txt
Revision: 133708
temp1.txt
!str! @
On the other hand, if I run it locally ( call ant target, which is executing batch, from CMD from my machine ), I got correct result(s)... Why? How to fix the batch to have same and correct result both in my machine and buildserver ( Jenkins CI ) job?
I am not daily Windows Shell coder, so any help would be highly appreciated. Oh, and plus that NewLine character
in the end of
Revision:
is also damn nasty one... Would be great to get rid of it :)
Upvotes: 0
Views: 264
Reputation: 7924
I think it's a terrible idea to have your build script aware of version control - those concerns should be separate.
Having said that, you're going to have a better time if you just set the output of svnversion
to a variable or even write it out to a file.
Upvotes: 2
Reputation: 70943
@echo off
setlocal enableextensions enabledelayedexpansion
rem and here starts the code
....
Maybe, this should work
If delayed expansion is off, !str!
(with the variable defined with valid content), returns !str!
. No delayed expansion, so no translation of !
variables.
BUT, echo %str% @ > temp1.txt
should work.
EDITED - for the nasty new line character
<temp2.txt set /p t2=
<nul set /p t2=%t2%> temp2.txt
Obviously, after the temp2.txt file has been generated
Upvotes: 0