I'm trying to create a shell script which gives a Json block which is used further. The Json block consists of the dynamic components assigned as variables. Below is the code snippet
failCount=$(cat jenkinstestResults.xml | grep -oP '(?<=failCount>)[^<]+') skipCount=$(cat jenkinstestResults.xml | grep -oP '(?<=skipCount>)[^<]+') echo $failCount echo $passCount echo $skipCount TESTS=("$passCount" "$failCount" "$skipCount") IFS='' read -r -d '' jsonBlock <<"EOF" ,{ "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "*${Jenkins.jobStatus}*\n*Jenkins Job:* <${Jenkins.buildUrl}|${Jenkins.buildFullDisplayName}[#${Jenkins.buildNumber}])>*" } }, { "type": "section", "fields": [ { "type": "mrkdwn", "text": "*Test Status:*\nPassed: ${TESTS[0]},Failed: ${TESTS[1]}, Skipped: ${TESTS[2]}" } ] }" EOF echo $jsonBlock
In the development environment, the Jenkins variables are resolving properly. But the issue is with the TEST variable whose values are extracted from the XML is not resolving in the final jsonBlock. It's getting printed as it is.
I'm relatively new to the Shell, kindly help.
echo "$jsonBlock"
. See Security implications of forgetting to quote a variable in bash/POSIX shells, particularly the links in the question.