如何从Windows批处理中保留Jenkins中的环境变量?

时间:2014-02-07 21:29:12

标签: windows batch-file jenkins environment-variables

我需要将Jenkins中的一些环境变量保存到稍后用于在Mac上设置环境变量的文件中。我假设以下批处理命令内容将像在cmd窗口中一样工作:

set | find "PROCESSOR"

来自cmd.exe生成

NUMBER_OF_PROCESSORS=2
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 44 Stepping 2, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=2c02

从Jenkins内部运行时会生成以下内容

C:\jenkins\workspace\P_PIL\ManageEnvironment>set   | find "PROCESSOR" 
find: unable to access "PROCESSOR": The system cannot find the file specified. 
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.
The process tried to write to a nonexistent pipe.

C:\jenkins\workspace\P_PIL\ManageEnvironment>exit 1 

我宁愿远离POWERSHELL,但如果这是唯一的方法,我想我可以试试。我只是不明白从命令行到Jenkins中的批处理命令的行为差异。

1 个答案:

答案 0 :(得分:2)

从错误我可以看出发现实际上是试图将“PROCESS”视为文件。我想这是因为set的输出没有正确管道传输,这与以下错误消息相匹配。这是因为目标管道已关闭。我认为它可能与find命令的行为有关。尝试使用findstr。