我对批次有疑问。
我在目录中有一个属性文件。其中有一个文本“BuildNumber = 0”。我想用“BuildNumber =%BUILD_NUMBER%”替换这个“BuildNumber = 0”。我使用以下脚本来实现此目的
@echo on
setlocal enabledelayedexpansion enableextensions
ATTRIB -r -s C:\bldarea\myfile\..\..\jenkinstest\abc.properties
CD C:\bldarea\myfile\file\Main_Releases\jenkinstest\
call :FindReplace "Buildnumber=0" "Buildnumber=%BUILD_NUMBER%" abc.properties
exit /b
:FindReplace <Buildnumber=0> <Buildnumber=%BUILD_NUMBER%> <abc.properties>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
)
)
del %temp%\_.vbs
exit /b
:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with
此脚本的问题是,它没有将BuildNumber = 0转换为当前的Build Number。
从代码行:
:FindReplace <Buildnumber=0> <Buildnumber=%BUILD_NUMBER%> <abc.properties>
如果我删除了%符号,那么它正在打印“BuildNumber =%BUILD_NUMBER%”,但“BuildNumber = 0”仍然存在于doc中。有人可以帮我帮我正确替换文本。
感谢。
答案 0 :(得分:0)
只需在此行中插入双倍百分比:
call :FindReplace "Buildnumber=0" "Buildnumber=%BUILD_NUMBER%" abc.properties
这样:
call :FindReplace "Buildnumber=0" "Buildnumber=%%BUILD_NUMBER%%" abc.properties