Greetings all,
Hope you are well and safe. I will need some pointers how to properly
escape the following piece of code into double quoted multi line shell step
```
#!/usr/bin/env bash
CURR_BL="foo_200227_203942"
HUB_URL="https://baz-baz.com:8045"
SEARCH_CSV_URL="${HUB_URL}/project_search.csv?query="${CURR_BL}"&scope=all"
CURL_OPTS="-s"
TTL_PRJ="$(curl "${CURL_OPTS}" ${SEARCH_CSV_URL} | awk -F , '{print $2}'|
wc -l)"
FIN_PRJ="$(curl "${CURL_OPTS}" ${SEARCH_CSV_URL} | awk -F , '{print $2}'|
grep Finished | wc -l)"
SUCC_RATE="$(awk -v succ_prj="${FIN_PRJ}" -v tl_prj="${TTL_PRJ}" 'BEGIN {
print int(( succ_prj / tl_prj )*100) }')"
LOG_PLACE="/foo/baz"
APPL_NAME="foobar"
CURR_VIEW="foo_200227_203942_seafood_int"
cd "${LOG_PLACE}/${APPL_NAME}/${CURR_VIEW}"/;
cat "${LOG_PLACE}/${APPL_NAME}/${CURR_VIEW}"/.build_[0-9]*/*.err >>
"${CURR_VIEW}_err.log"
mail -a "${CURR_VIEW}_err.log" -s "Code quality build stats and error logs
attached for ${CURR_VIEW}" [email protected] << EOF
================Printing Code quality build stats:==================
Total projects for ${CURR_BL} is: ${TTL_PRJ}
Finished projects for ${CURR_BL} is: ${FIN_PRJ}
Success rate in percentage is: ${SUCC_RATE}
EOF
```
When running the above script as Jenkins shell step with """ I get the
error
illegal string body character after dollar sign;
solution: either escape a literal dollar sign "\$5" or
bracket the value expression "${5}" @ line 13, column 86.
earch.csv?query="${CURR_BL}"&scope=a
Sample code with the error trigger is included
```
pipeline {
agent {label 'baz'}
stages {
stage('Test') {
steps {
script{
sh"""#!/usr/bin/env bash
CURR_BL="foo_200227_203942"
HUB_URL="https://baz-baz.com:8045"
SEARCH_CSV_URL="${HUB_URL}/project_search.csv?query="${CURR_BL}"&scope=all"
CURL_OPTS="-s"
TTL_PRJ="$(curl "${CURL_OPTS}" ${SEARCH_CSV_URL} | awk
-F , '{print $2}'| wc -l)"
FIN_PRJ="$(curl "${CURL_OPTS}" ${SEARCH_CSV_URL} | awk
-F , '{print $2}'| grep Finished | wc -l)"
SUCC_RATE="$(awk -v succ_prj="${FIN_PRJ}" -v
tl_prj="${TTL_PRJ}" 'BEGIN { print int(( succ_prj / tl_prj )*100) }')"
LOG_PLACE="/foo/baz"
APPL_NAME="foobar"
CURR_VIEW="foo_200227_203942_seafood_int"
cd "${LOG_PLACE}/${APPL_NAME}/${CURR_VIEW}"/;
cat
"${LOG_PLACE}/${APPL_NAME}/${CURR_VIEW}"/.build_[0-9]*/*.err >>
"${CURR_VIEW}_err.log"
mail -a "${CURR_VIEW}_err.log" -s "Code quality build
stats and error logs attached for ${CURR_VIEW}" [email protected] << EOF
================Printing Code quality build
stats:==================
Total projects for ${CURR_BL} is: ${TTL_PRJ}
Finished projects for ${CURR_BL} is: ${FIN_PRJ}
Success rate in percentage is: ${SUCC_RATE}
EOF
"""
}
}
}
}
}
```
So it seems I can't make groovy enough groovy using """. With ''' it works
fine. However I prefer to educate myself if possible. Thanks for making
this happen.