@@ -1029,176 +1029,13 @@ EOF
10291029 ) '''
10301030 }
10311031 }
1032- // If this is a Pull request send the CI link as a comment on it
1033- stage(' Pull Request Comment' ) {
1034- when {
1035- not {environment name : ' CHANGE_ID' , value : ' ' }
1036- environment name : ' CI_TEST_ATTEMPTED' , value : ' true'
1037- }
1038- steps {
1039- sh ''' #! /bin/bash
1040- # Function to retrieve JSON data from URL
1041- get_json() {
1042- local url="$1"
1043- local response=$(curl -s "$url")
1044- if [ $? -ne 0 ]; then
1045- echo "Failed to retrieve JSON data from $url"
1046- return 1
1047- fi
1048- local json=$(echo "$response" | jq .)
1049- if [ $? -ne 0 ]; then
1050- echo "Failed to parse JSON data from $url"
1051- return 1
1052- fi
1053- echo "$json"
1054- }
1055-
1056- build_table() {
1057- local data="$1"
1058-
1059- # Get the keys in the JSON data
1060- local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1061-
1062- # Check if keys are empty
1063- if [ -z "$keys" ]; then
1064- echo "JSON report data does not contain any keys or the report does not exist."
1065- return 1
1066- fi
1067-
1068- # Build table header
1069- local header="| Tag | Passed |\\ n| --- | --- |\\ n"
1070-
1071- # Loop through the JSON data to build the table rows
1072- local rows=""
1073- for build in $keys; do
1074- local status=$(echo "$data" | jq -r ".[\\ "$build\\ "].test_success")
1075- if [ "$status" = "true" ]; then
1076- status="✅"
1077- else
1078- status="❌"
1079- fi
1080- local row="| "$build" | "$status" |\\ n"
1081- rows="${rows}${row}"
1082- done
1083-
1084- local table="${header}${rows}"
1085- local escaped_table=$(echo "$table" | sed 's/\" /\\\\ "/g')
1086- echo "$escaped_table"
1087- }
1088-
1089- if [[ "${CI}" = "true" ]]; then
1090- # Retrieve JSON data from URL
1091- data=$(get_json "$CI_JSON_URL")
1092- # Create table from JSON data
1093- table=$(build_table "$data")
1094- echo -e "$table"
1095-
1096- curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1097- -H "Accept: application/vnd.github.v3+json" \
1098- "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1099- -d "{\\ "body\\ ": \\ "I am a bot, here are the test results for this PR: \\ n${CI_URL}\\ n${SHELLCHECK_URL}\\ n${table}\\ "}"
1100- else
1101- curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1102- -H "Accept: application/vnd.github.v3+json" \
1103- "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1104- -d "{\\ "body\\ ": \\ "I am a bot, here is the pushed image/manifest for this PR: \\ n\\ n\\ `${GITHUBIMAGE}:${META_TAG}\\ `\\ "}"
1105- fi
1106- '''
1107-
1108- }
1109- }
11101032 }
11111033 /* ######################
1112- Comment on PR (failed test) and Send status to Discord
1034+ Comment on PR and Send status to Discord
11131035 ###################### */
11141036 post {
11151037 always {
11161038 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- }
1137-
1138- build_table() {
1139- local data="$1"
1140-
1141- # Get the keys in the JSON data
1142- local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1143-
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
1149-
1150- # Build table header
1151- local header="| Tag | Passed |\\ n| --- | --- |\\ n"
1152-
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
1165-
1166- local table="${header}${rows}"
1167- local escaped_table=$(echo "$table" | sed 's/\" /\\\\ "/g')
1168- echo "$escaped_table"
1169- }
1170-
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"
1177-
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- }
1190- }
1191- }
1192- }
1193- }
1194- sh ''' #!/bin/bash
1195- rm -rf /config/.ssh/id_sign
1196- rm -rf /config/.ssh/id_sign.pub
1197- git config --global --unset gpg.format
1198- git config --global --unset user.signingkey
1199- git config --global --unset commit.gpgsign
1200- '''
1201- script{
12021039 env. JOB_DATE = sh(
12031040 script : ''' date '+%Y-%m-%dT%H:%M:%S%:z' ''' ,
12041041 returnStdout : true ). trim()
@@ -1241,6 +1078,87 @@ EOF
12411078 "username": "Jenkins"}' ${BUILDS_DISCORD} '''
12421079 }
12431080 }
1081+ script {
1082+ if (env. GITHUBIMAGE =~ / lspipepr/ ){
1083+ if (env. CI_TEST_ATTEMPTED == " true" ){
1084+ sh ''' #! /bin/bash
1085+ # Function to retrieve JSON data from URL
1086+ get_json() {
1087+ local url="$1"
1088+ local response=$(curl -s "$url")
1089+ if [ $? -ne 0 ]; then
1090+ echo "Failed to retrieve JSON data from $url"
1091+ return 1
1092+ fi
1093+ local json=$(echo "$response" | jq .)
1094+ if [ $? -ne 0 ]; then
1095+ echo "Failed to parse JSON data from $url"
1096+ return 1
1097+ fi
1098+ echo "$json"
1099+ }
1100+
1101+ build_table() {
1102+ local data="$1"
1103+
1104+ # Get the keys in the JSON data
1105+ local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1106+
1107+ # Check if keys are empty
1108+ if [ -z "$keys" ]; then
1109+ echo "JSON report data does not contain any keys or the report does not exist."
1110+ return 1
1111+ fi
1112+
1113+ # Build table header
1114+ local header="| Tag | Passed |\\ n| --- | --- |\\ n"
1115+
1116+ # Loop through the JSON data to build the table rows
1117+ local rows=""
1118+ for build in $keys; do
1119+ local status=$(echo "$data" | jq -r ".[\\ "$build\\ "].test_success")
1120+ if [ "$status" = "true" ]; then
1121+ status="✅"
1122+ else
1123+ status="❌"
1124+ fi
1125+ local row="| "$build" | "$status" |\\ n"
1126+ rows="${rows}${row}"
1127+ done
1128+
1129+ local table="${header}${rows}"
1130+ local escaped_table=$(echo "$table" | sed 's/\" /\\\\ "/g')
1131+ echo "$escaped_table"
1132+ }
1133+
1134+ if [[ "${CI}" = "true" ]]; then
1135+ # Retrieve JSON data from URL
1136+ data=$(get_json "$CI_JSON_URL")
1137+ # Create table from JSON data
1138+ table=$(build_table "$data")
1139+ echo -e "$table"
1140+
1141+ curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1142+ -H "Accept: application/vnd.github.v3+json" \
1143+ "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1144+ -d "{\\ "body\\ ": \\ "I am a bot, here are the test results for this PR: \\ n${CI_URL}\\ n${SHELLCHECK_URL}\\ n${table}\\ "}"
1145+ else
1146+ curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1147+ -H "Accept: application/vnd.github.v3+json" \
1148+ "https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1149+ -d "{\\ "body\\ ": \\ "I am a bot, here is the pushed image/manifest for this PR: \\ n\\ n\\ `${GITHUBIMAGE}:${META_TAG}\\ `\\ "}"
1150+ fi
1151+ '''
1152+ }
1153+ }
1154+ }
1155+ sh ''' #!/bin/bash
1156+ rm -rf /config/.ssh/id_sign
1157+ rm -rf /config/.ssh/id_sign.pub
1158+ git config --global --unset gpg.format
1159+ git config --global --unset user.signingkey
1160+ git config --global --unset commit.gpgsign
1161+ '''
12441162 }
12451163 cleanup {
12461164 sh ''' #! /bin/bash
0 commit comments