简体   繁体   English

如果从Jenkins CI作业执行,批处理返回不同的结果

[英]Batch returns different result, if executed from Jenkins CI job

I am executing batch file from apache ant build.xml, running from Jenkins CI job ( Win 7 x64 Ent SP1 ). 我从apache ant build.xml执行批处理文件,从Jenkins CI作业(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: BrandingText.PROPERTIES:

 @ Revision: 133708

temp3.txt: temp3.txt:

!str! @ 
Revision: 133708

temp2.txt temp2.​​txt

Revision: 133708

temp1.txt 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? 另一方面,如果我在本地运行它(从我的机器上调用CM目标,从CMD执行批处理),我得到了正确的结果......为什么? How to fix the batch to have same and correct result both in my machine and buildserver ( Jenkins CI ) job? 如何在我的机器和buildserver(Jenkins CI)作业中修复批处理以获得相同和正确的结果?

I am not daily Windows Shell coder, so any help would be highly appreciated. 我不是每天的Windows Shell编码器,所以任何帮助都将受到高度赞赏。 Oh, and plus that NewLine character in the end of 哦,加上NewLine character到底

Revision: 修订:

is also damn nasty one... Would be great to get rid of it :) 也是该死的令人讨厌的......很高兴摆脱它:)

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. 话虽如此,如果你只是将svnversion的输出设置为变量或者甚至将其写入文件,你将会有更好的时间。

@echo off
    setlocal enableextensions enabledelayedexpansion
    rem and here starts the code
    ....

Maybe, this should work 也许,这应该工作

If delayed expansion is off, !str! 如果延迟扩展关闭, !str! (with the variable defined with valid content), returns !str! (使用有效内容定义的变量),返回!str! . No delayed expansion, so no translation of ! 没有延迟扩展,所以没有翻译! variables. 变量。

BUT, echo %str% @ > temp1.txt should work. 但是, echo %str% @ > temp1.txt应该可以工作。

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 显然,在生成了temp2.​​txt文件之后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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