【问题标题】:How do I persist environment variables in Jenkins from a Windows batch?如何从 Windows 批处理中持久保存 Jenkins 中的环境变量?
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-26
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 2018-09-05
    • 2011-04-17
    相关资源
    最近更新 更多