5

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for pointing "\" to escape the line break, which populates the OPS with all the content without line breaks. But I want formatted content , which includes the lines breaks, as I want to include it in the Email Body . Any inputs ?
Mh, I missed the fact that line terminators also being discarded. You could try terminating the lines with \n\ or \r\n\ instead. ("Characters in keys and elements can be represented in escape sequences similar to those used for character and string literals (see sections 3.3 and 3.10.6 of The Java™ Language Specification).")
(You probably also have to escape any other backslash in your input to avoid unexpected behaviour)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.