Skip to content

Commit aeb1a37

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

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

hack/ci-e2e-lib.sh

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

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 [[ $(find "${ORIGINAL_ARTIFACTS}" -maxdepth 1 -name 'junit\.*\.xmla' | wc -l) -gt 0 ]]; 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)