@@ -1113,78 +1113,80 @@ EOF
11131113 ###################### */
11141114 post {
11151115 always {
1116- if (env. EXIT_STATUS != " ABORTED" ){
1117- if (currentBuild. currentResult != " SUCCESS" ){
1118- if (env. GITHUBIMAGE =~ / lspipepr/ ){
1119- if (env. CI_TEST_ATTEMPTED == " true" ){
1120- sh ''' #! /bin/bash
1121- # Function to retrieve JSON data from URL
1122- get_json() {
1123- local url="$1"
1124- local response=$(curl -s "$url")
1125- if [ $? -ne 0 ]; then
1126- echo "Failed to retrieve JSON data from $url"
1127- return 1
1128- fi
1129- local json=$(echo "$response" | jq .)
1130- if [ $? -ne 0 ]; then
1131- echo "Failed to parse JSON data from $url"
1132- return 1
1133- fi
1134- echo "$json"
1135- }
1116+ script {
1117+ if (env. EXIT_STATUS != " ABORTED" ){
1118+ if (currentBuild. currentResult != " SUCCESS" ){
1119+ if (env. GITHUBIMAGE =~ / lspipepr/ ){
1120+ if (env. CI_TEST_ATTEMPTED == " true" ){
1121+ sh ''' #! /bin/bash
1122+ # Function to retrieve JSON data from URL
1123+ get_json() {
1124+ local url="$1"
1125+ local response=$(curl -s "$url")
1126+ if [ $? -ne 0 ]; then
1127+ echo "Failed to retrieve JSON data from $url"
1128+ return 1
1129+ fi
1130+ local json=$(echo "$response" | jq .)
1131+ if [ $? -ne 0 ]; then
1132+ echo "Failed to parse JSON data from $url"
1133+ return 1
1134+ fi
1135+ echo "$json"
1136+ }
11361137
1137- build_table() {
1138- local data="$1"
1138+ build_table() {
1139+ local data="$1"
11391140
1140- # Get the keys in the JSON data
1141- local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1141+ # Get the keys in the JSON data
1142+ local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
11421143
1143- # Check if keys are empty
1144- if [ -z "$keys" ]; then
1145- echo "JSON report data does not contain any keys or the report does not exist."
1146- return 1
1147- fi
1144+ # Check if keys are empty
1145+ if [ -z "$keys" ]; then
1146+ echo "JSON report data does not contain any keys or the report does not exist."
1147+ return 1
1148+ fi
11481149
1149- # Build table header
1150- local header="| Tag | Passed |\\ n| --- | --- |\\ n"
1150+ # Build table header
1151+ local header="| Tag | Passed |\\ n| --- | --- |\\ n"
11511152
1152- # Loop through the JSON data to build the table rows
1153- local rows=""
1154- for build in $keys; do
1155- local status=$(echo "$data" | jq -r ".[\\ "$build\\ "].test_success")
1156- if [ "$status" = "true" ]; then
1157- status="✅"
1158- else
1159- status="❌"
1160- fi
1161- local row="| "$build" | "$status" |\\ n"
1162- rows="${rows}${row}"
1163- done
1153+ # Loop through the JSON data to build the table rows
1154+ local rows=""
1155+ for build in $keys; do
1156+ local status=$(echo "$data" | jq -r ".[\\ "$build\\ "].test_success")
1157+ if [ "$status" = "true" ]; then
1158+ status="✅"
1159+ else
1160+ status="❌"
1161+ fi
1162+ local row="| "$build" | "$status" |\\ n"
1163+ rows="${rows}${row}"
1164+ done
11641165
1165- local table="${header}${rows}"
1166- local escaped_table=$(echo "$table" | sed 's/\" /\\\\ "/g')
1167- echo "$escaped_table"
1168- }
1166+ local table="${header}${rows}"
1167+ local escaped_table=$(echo "$table" | sed 's/\" /\\\\ "/g')
1168+ echo "$escaped_table"
1169+ }
11691170
1170- if [[ "${CI}" = "true" ]]; then
1171- # Retrieve JSON data from URL
1172- data=$(get_json "$CI_JSON_URL")
1173- # Create table from JSON data
1174- table=$(build_table "$data")
1175- echo -e "$table"
1171+ if [[ "${CI}" = "true" ]]; then
1172+ # Retrieve JSON data from URL
1173+ data=$(get_json "$CI_JSON_URL")
1174+ # Create table from JSON data
1175+ table=$(build_table "$data")
1176+ echo -e "$table"
11761177
1177- curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1178- -H "Accept: application/vnd.github.v3+json" \
1179- "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1180- -d "{\\ "body\\ ": \\ "I am a bot, here are the test results for this PR: \\ n${CI_URL}\\ n${SHELLCHECK_URL}\\ n${table}\\ "}"
1181- else
1182- curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1183- -H "Accept: application/vnd.github.v3+json" \
1184- "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1185- -d "{\\ "body\\ ": \\ "I am a bot, here is the pushed image/manifest for this PR: \\ n\\ n\\ `${GITHUBIMAGE}:${META_TAG}\\ `\\ "}"
1186- fi
1187- '''
1178+ curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1179+ -H "Accept: application/vnd.github.v3+json" \
1180+ "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1181+ -d "{\\ "body\\ ": \\ "I am a bot, here are the test results for this PR: \\ n${CI_URL}\\ n${SHELLCHECK_URL}\\ n${table}\\ "}"
1182+ else
1183+ curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1184+ -H "Accept: application/vnd.github.v3+json" \
1185+ "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1186+ -d "{\\ "body\\ ": \\ "I am a bot, here is the pushed image/manifest for this PR: \\ n\\ n\\ `${GITHUBIMAGE}:${META_TAG}\\ `\\ "}"
1187+ fi
1188+ '''
1189+ }
11881190 }
11891191 }
11901192 }
0 commit comments