Skip to content

Commit 1b91f53

Browse files
committed
hack/e2e.sh create a junit file when running e2e.sh
1 parent b243723 commit 1b91f53

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

hack/ci-e2e-lib.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,51 @@ 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+
status="failed"
219+
succeeded="false"
220+
if [[ "$failure" == 0 ]]; then
221+
status="passed"
222+
succeeded="true"
223+
fi
224+
timestamp="$(date -u +%Y-%m-%dT%H:%M:%S)"
225+
# Write header
226+
cat > "$output_file" << EOF
227+
<?xml version="1.0" encoding="UTF-8"?>
228+
<testsuites name="e2e.sh Suite" tests="1" failures="${failure}" errors="0" skipped="0" time="0.1">
229+
<testsuite name="Preparation" tests="1" failures="${failure}" errors="0" skipped="0" time="0.1" timestamp="${timestamp}">
230+
<properties>
231+
<property name="SuiteSucceeded" value="${succeeded}"/>
232+
</properties>
233+
<testcase name="hack_e2e_sh" classname="Preparation.hack_e2e_sh" status="${status}" time="0.1">
234+
EOF
235+
# Write content
236+
if [[ "$failure" == 0 ]]; then
237+
# No error, just write a message to the output file.
238+
echo "<system-out>hack/e2e.sh script succeeded</system-out>" >> ${output_file}
239+
else
240+
failure_data_file="${3}"
241+
cat >> "$output_file" << EOF
242+
<failure message="hack/e2e.sh script failed">
243+
<![CDATA[
244+
EOF
245+
# Erorr case, write the content of the failure data file to the output file.
246+
# Note: the sed ensures that the content does not close the CDATA section.
247+
cat "${failure_data_file}" | sed 's/]]>/]]>]]&gt;<![CDATA[/g' >> "$output_file"
248+
cat >> "$output_file" << EOF
249+
]]>
250+
</failure>
251+
EOF
252+
fi
253+
# Write footer
254+
cat >> "$output_file" << EOF
255+
</testcase>
256+
</testsuite>
257+
</testsuites>
258+
EOF
259+
260+
}

hack/e2e.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ if [[ "${ARTIFACTS}" != "${REPO_ROOT}/_artifacts" ]]; then
3636
ARTIFACTS=$(mktemp -d)
3737
fi
3838

39+
E2E_SH_LOG_FILE="e2e-sh-log.txt"
40+
41+
# Redirect all output of this script additionally to a file in artifacts,
42+
# so we can create a junit file with its content in case of general CI failures.
43+
# This way the bash script's log can be analyzed using k8s-triage.
44+
exec &> >(stdbuf -oL tee "${ARTIFACTS}/${E2E_SH_LOG_FILE}")
45+
3946
# shellcheck source=./hack/ensure-go.sh
4047
source "${REPO_ROOT}/hack/ensure-go.sh"
4148

@@ -52,7 +59,9 @@ on_exit() {
5259
[[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}"
5360

5461
# If Boskos is being used then release the vsphere project.
55-
[ -z "${BOSKOS_HOST:-}" ] || docker run -e VSPHERE_USERNAME -e VSPHERE_PASSWORD gcr.io/k8s-staging-capi-vsphere/extra/boskosctl:latest release --boskos-host="${BOSKOS_HOST}" --resource-owner="${BOSKOS_RESOURCE_OWNER}" --resource-name="${BOSKOS_RESOURCE_NAME}" --vsphere-server="${VSPHERE_SERVER}" --vsphere-tls-thumbprint="${VSPHERE_TLS_THUMBPRINT}" --vsphere-folder="${BOSKOS_RESOURCE_FOLDER}" --vsphere-resource-pool="${BOSKOS_RESOURCE_POOL}"
62+
if [[ "${BOSKOS_HOST:-}" != "" && "${BOSKOS_RESOURCE_NAME:-}" != "" ]]; then
63+
docker run -e VSPHERE_USERNAME -e VSPHERE_PASSWORD gcr.io/k8s-staging-capi-vsphere/extra/boskosctl:latest release --boskos-host="${BOSKOS_HOST}" --resource-owner="${BOSKOS_RESOURCE_OWNER}" --resource-name="${BOSKOS_RESOURCE_NAME}" --vsphere-server="${VSPHERE_SERVER}" --vsphere-tls-thumbprint="${VSPHERE_TLS_THUMBPRINT}" --vsphere-folder="${BOSKOS_RESOURCE_FOLDER}" --vsphere-resource-pool="${BOSKOS_RESOURCE_POOL}"
64+
fi
5665
fi
5766

5867
# Cleanup VSPHERE_PASSWORD from temporary artifacts directory.
@@ -97,6 +106,18 @@ on_exit() {
97106
# Move all artifacts to the original artifacts location.
98107
mv "${ARTIFACTS}"/* "${ORIGINAL_ARTIFACTS}/"
99108
fi
109+
110+
# Create a junit file for running this script.
111+
112+
# Delete output file from this script because it contains a duplicate output
113+
if ls -1 "${ORIGINAL_ARTIFACTS}" 2>/dev/null | grep -q "^junit\..*\.xml$"; then
114+
# There are junit files in artifacts
115+
junit::createJunitReportE2Esh 0 "${ORIGINAL_ARTIFACTS}/junit.e2e-sh.xml"
116+
else
117+
junit::createJunitReportE2Esh 1 "${ORIGINAL_ARTIFACTS}/junit.e2e-sh.xml" "${ORIGINAL_ARTIFACTS}/${E2E_SH_LOG_FILE}"
118+
fi
119+
# Cleanup the additionally written log file, the same content will be in build-log.txt.
120+
rm "${ORIGINAL_ARTIFACTS}/${E2E_SH_LOG_FILE}"
100121
}
101122

102123
trap on_exit EXIT

0 commit comments

Comments
 (0)