I would like to remotely change a Jenkins build description. I have my script all set and ready except for one tiny problem: Multiple line descriptions.
I am us
I played around with this for a long while...
First, instead of doing this:
new_description="$new_description<br/>
$old_description"
to append or prepend the line, I used printf
:
new_description="$(printf "$new_description\r\n$old_description")"
By using printf
, I put a <CR><LF>
instead of just a <LF>
in my description line separator. This way, I don't have a jumble of <NL>
and <CR><NL>
and I'm no longer dependent upon the operating system's definition of the line break.
The sed
command took me a long, long time to figure out. I tried all sorts of things:
old_description=$(sed 's/\\r\\n/\r\n/g' <<<$old_description)
But, nothing seemed to work... I tried the -E
flag which allows me to use the extended regular expressions, but it kept interpreting \r\n
as replacing \\r\\n
with literal 'rn
.
After several hours of this, I finally tried double quotation marks instead of single quotation marks:
old_description=$(sed "s/\\r\\n/\r\n/g" <<<$old_description)
That worked! You normally use single quotation marks with sed to protect the regular expression from interpolation. However, the single quotes were also killing the interpolation of \r\n
as <CR><LF>
. Changing them with double quotes solved the problem.