I would like to remotely modify the Jenkins build description. I have my script whole set and ready, with the exception of one tiny problem: a few line descriptions.
I use the REST API and JSON in Jenkins to load the old description:
old_description=$(curl -s --user "$USER:$PASSWORD" --data-urlencode "tree=description" \ "$jenkins_url/job/$job_name/$build_number/api/json") old_description=${old_description#*:\"}
The curl command extends:
<font color=blue><b>At first you don't succeed. Try again</b></font><br/> \r\n<font color=gold><b>At first you don't succeed. Try again</b></font><br/> \r\n<font color=green><b>At first you don't succeed. Try again</b></font>
(Note: I added line breaks to make it easier to read above. It pulls out as one line).
\r\n are single lines, so I do this:
old_description=$(sed 's/\\r\\n/\ /g' <<<$old_description)
And that will change $old_description to:
font color=blue><b>At first you don't succeed. Try again</b></font><br/> <font color=gold><b>At first you don't succeed. Try again</b></font><br/> <font color=green><b>At first you don't succeed. Try again</b></font>
(NOTE: Newlines are part of the value. This is a three-line description.)
My program (depending on the command line parameters) can replace, add or add a new description to the assembly:
if [ "$prepend_flag" -a -n "$old_description" ] #Prepend new description to old description then new_description="$new_description<br/> $old_description" elif [ "$append_flag" -a -n "$old_description" ] #Append new description to old description then new_description="$old_description<br/> $new_description" fi
Now I will redo the description:
if curl -u $USER:$PASSWORD --data-urlencode "description=$new_description" \ --data-urlencode "Submit=Submit" \ "$jenkins_url/job/$job_name/$build_number/submitDescription" then echo "Description successfully changed on Build #$build_number in Jenkins job $job_name" else echo "WARNING: Description was not set. Manually change the descripiton of the build" echo " for Build #$build_number in Jenkins job $job_name" fi
If I add or add a new description for the first time, I get this in Jenkins:
<font color=blue><b>At first you don't succeed. Try again</b></font><br/> <font color=gold><b>At first you don't succeed. Try again</b></font><br/> <font color=green><b>At first you don't succeed. Try again</b></font><br/> <font color=red><b>My new description</b></font><br/>
Looks good. Next time it will not work. I get the following:
<font color=blue><b>At first you don't succeed. Try again</b></font><br/>\n<font color=gold><b>At first you don't succeed. Try again</b></font><br/>\n<font color=green><b>At first you don't succeed. Try again</b></font><br/>\n<font color=red><b>My new description</b></font><br/> <font color=blue><b>My new new description</b></font>
Note the mapping \n .
How can I fix this problem?
I put the whole program in pastebin .