I'm able to run the following shell script but couldn't run from Jenkins pipeline code.
Try 1.
node('buildnode') {
def value = "Myvalue"
def key = "Mykey"
sh '''
DATA=$(printf "%-50s \"$key\"" "$value")
echo "$DATA"
'''
}
output:
++ printf '%-50s ' ''
+ DATA='
Try 2:
Tried with sh " " "
DATA=$(printf "%-50s \"$key\"" "$value")
echo "$DATA"
" " "
output: :
illegal string body character after dollar sign; solution: either escape a literal dollar sign
"\$5"
or bracket the value expression"${5}"
Can someone help me?
This should work.
You also need to escape $ when calling new subshell under
""" """