File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -210,3 +210,38 @@ kind::prepullImage () {
210210 echo " + image $image already present in the system, skipping pre-pull"
211211 fi
212212}
213+
214+ # junit::createJunitReportE2Esh creates a junit report file for the e2e.sh script.
215+ junit::createJunitReportE2Esh () {
216+ failure=" $1 "
217+ output_file=" $2 "
218+ failure_data_file=" $3 "
219+ timestamp=" $( date -u +%Y-%m-%dT%H:%M:%S) "
220+ # Write header
221+ cat > " $output_file " << EOF
222+ <?xml version="1.0" encoding="UTF-8"?>
223+ <testsuites name="e2e.sh Suite" tests="1" failures="${failure} " errors="0" skipped="0" time="0.1">
224+ <testsuite name="Preparation" tests="1" failures="${failure} " errors="0" skipped="0" time="0.1" timestamp="${timestamp} ">
225+ <testcase name="hack_e2e_sh" classname="Preparation.hack_e2e_sh" time="0.1">
226+ <system-out>
227+ <![CDATA[
228+ EOF
229+ # Write content
230+ if [[ " $failure " == 0 ]]; then
231+ # No error, just write a message to the output file.
232+ echo " No error, see e2e-sh.log for full output" >> ${output_file}
233+ else
234+ # Erorr case, write the content of the failure data file to the output file.
235+ # Note: the sed ensures that the content does not close the CDATA section.
236+ cat " ${failure_data_file} " | sed ' s/]]>/]]>]]><![CDATA[/g' >> " $output_file "
237+ fi
238+ # Write footer
239+ cat >> " $output_file " << EOF
240+ ]]>
241+ </system-out>
242+ </testcase>
243+ </testsuite>
244+ </testsuites>
245+ EOF
246+
247+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ if [[ "${ARTIFACTS}" != "${REPO_ROOT}/_artifacts" ]]; then
3636 ARTIFACTS=$( mktemp -d)
3737fi
3838
39+ # Redirect all output of this script additionally to a file in artifacts,
40+ # so we can create a junit file with its content in case of general CI failures.
41+ # This way the bash script's log can be analyzed using k8s-triage.
42+ exec & > >( tee script.log)
43+
3944# shellcheck source=./hack/ensure-go.sh
4045source " ${REPO_ROOT} /hack/ensure-go.sh"
4146
@@ -97,6 +102,18 @@ on_exit() {
97102 # Move all artifacts to the original artifacts location.
98103 mv " ${ARTIFACTS} " /* " ${ORIGINAL_ARTIFACTS} /"
99104 fi
105+
106+ # Create a junit file for running this script.
107+
108+ # Delete output file from this script because it contains a duplicate output
109+ if ls -1 " ${ORIGINAL_ARTIFACTS} " 2> /dev/null | grep -q " ^junit\..*\.xml$" ; then
110+ # There are junit files in artifacts
111+ junit::createJunitReportE2Esh 0 " ${ORIGINAL_ARTIFACTS} /junit.e2e-sh.xml"
112+ else
113+ junit::createJunitReportE2Esh 1 " ${ORIGINAL_ARTIFACTS} /junit.e2e-sh.xml" " ${ORIGINAL_ARTIFACTS} /e2e-sh.log"
114+ fi
115+ # Cleanup the additionally written log file, the same content will be in build-log.txt.
116+ rm " ${ORIGINAL_ARTIFACTS} /e2e-sh.log"
100117}
101118
102119trap on_exit EXIT
You can’t perform that action at this time.
0 commit comments