Modifying Jenkins Description for a build

最后都变了- 提交于 2019-12-02 07:28:41

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!