Jeff Hutton
Jeff Hutton

Reputation: 166

How do I persist environment variables in Jenkins from a Windows batch?

I need to persist some environment variables in Jenkins to a file that is later used to set environment variables on a Mac. I assumed the following batch command contents would work just like it does in a cmd window:

set | find "PROCESSOR"

which from cmd.exe generates

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

when run from within Jenkins it produces the following

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 

I'd rather stay away from POWERSHELL, but if that's the only way to do it, I suppose I can try. I just don't understand the difference in behavior from the command line to a batch command within Jenkins.

Upvotes: 0

Views: 1930

Answers (1)

Andy Chen
Andy Chen

Reputation: 361

From the error I can tell find was actually trying to treat "PROCESS" as an file. I guess it is because the output of set didn't get piped correctly, which matches the following error messages. This is because the target pipe has been closed. I think it may relate to the behavior of find command. Try to use findstr instead.

Upvotes: 2

Related Questions