【发布时间】:2014-03-05 11:24:06
【问题描述】:
我需要将 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 中从命令行到批处理命令的行为差异。
【问题讨论】:
-
您确定在您的 Jenkins 环境中调用的
find与您使用的相同吗?您的用户使用的路径可能与您的 Jenkins 帐户使用的路径不同。尝试更改您的批处理文件以仅回显路径是什么,并查看在出现早于C:\windows\system32的路径中是否还有另一个find。或者,只需显式调用C:\windows\system32\find.exe。 -
呃。谢谢。你是对的。我从命令行以与 Jenkins 使用的用户不同的用户身份执行操作。 Jenkins 用户在其路径上有一些 UNIX 实用程序,并且正在使用 UNIX 样式的查找。我选择使用下面建议的 findstr 以消除歧义。
标签: windows batch-file jenkins environment-variables