I have a Jenkins job with an execute shell box. In the execute shell I use bash instead of dash (sh). In the execute shell I have strings which are supposed to be interpreted as they contain escape sequences (in this case the new line: n
), so here is an example execute shell:
#!/bin/bash set -x #echo on git fetch ... git commit -m "Merging $DEVELOPEMENTBRANCH into $INITIALBRANCHnnThis is an example second paragraph." ...
My problem here is that the script block is interpreted/replaced by Jenkins in a way that it changes its behavior, to be specific it replaces the variables and replaces the double quotes with single quotes so in the console output it looks like this:
[4] $ /bin/bash /tmp/hudson7542128982632971668.sh + git fetch ... + git commit -m 'Merging my_feature into developnnThis is an example second paragraph' ...
But in this way the n
part won’t be interpreted because of the single quotes. What is the trick here? I want to preserve the double quotes or at least interpret the n
sequences.
Advertisement
Answer
git commit -m "A multi-linenncommit message"
will not produce a multi-line
commit message anyway. The commit message will be, literally, A multi-linenncommit message
.
Double-quotes do not cause bash
to interpret printf
escape-sequences.
To get a multi-line commit-message you need:
git commit -m "`printf "A multi-linenncommit message"`"
This works fine in a Jenkins shell step.