Alferd Nobel
Alferd Nobel

Reputation: 3949

Jenkins EnvInject plugin - Environment variable value containing multiple lines

I followed the suggestions from this post on how to use the EnvInject plugin to create and set Jenkins environment variables. I'm using the "Inject environment variables" in post build step and set "Properties File Path"

The windows batch script create a environment variable OPS and writes it to a property file : results.txt which contains multiple lines , like :

OPS= This is line one,
This is two
This is three 

Challenge: OPS picks up only the first line from results.txt and skips the rest of the lines.

How do I set OPS have all the lines as its value ?

cd C:\To\Test\Class\Path
java utilities.LogExtractor>ops.txt
@echo off
setlocal EnableDelayedExpansion
set LF=^


rem *** Two empty lines are required for the linefeed
FOR /F "delims=" %%a in (ops.txt) do (
  set var=!var!!LF!%%a
)
set var=!var!!LF!
echo OPS=!var! > %JENKINS_HOME%\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\results.txt

and I set the "Properties File Path" to %JENKINS_HOME%\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\results.txt

Upvotes: 5

Views: 3002

Answers (1)

phi1010
phi1010

Reputation: 677

From the source code, I'd say it uses java.util.Properties to load the file, calling the load method. The documentation says you can escape a line break with a backslash, so using

OPS= This is line one,\
This is two\
This is three 

should be sufficient. (Be careful, whitespace at the beginning of the line is ommitted.)

Upvotes: 2

Related Questions