Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 456
Alferd Nobel Avatar asked Oct 29 '22 01:10

Alferd Nobel


1 Answers

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.)

like image 110
phi1010 Avatar answered Nov 15 '22 04:11

phi1010