Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions hack/ci-e2e-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,47 @@ kind::prepullImage () {
echo "+ image $image already present in the system, skipping pre-pull"
fi
}

# junit::createJunitReportE2Esh creates a junit report file for the e2e.sh script.
junit::createJunitReportE2Esh() {
failure="$1"
output_file="$2"
timestamp="$(date -u +%Y-%m-%dT%H:%M:%S)"

# Set variables to use for a successful run.
status="passed"
body="<system-out>hack/e2e.sh script succeeded</system-out>"

# Change variables to use for a failed run.
if [[ "$failure" != 0 ]]; then
status="failed"
body="$(junit::createJunitReportE2EshFailureBody "${3}")"
fi

# Write header
cat > "$output_file" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="e2e.sh Suite" tests="1" failures="${failure}" errors="0" skipped="0" time="0.1">
<testsuite name="Preparation" tests="1" failures="${failure}" errors="0" skipped="0" time="0.1" timestamp="${timestamp}">
<testcase name="hack_e2e_sh" classname="Preparation.hack_e2e_sh" status="${status}" time="0.1">
${body}
</testcase>
</testsuite>
</testsuites>
EOF
}

junit::createJunitReportE2EshFailureBody() {
failure_data_file="${1}"
cat << EOF
<failure message="hack/e2e.sh script failed">
<![CDATA[
EOF
# Erorr case, write the content of the failure data file to the output file.
# Note: the sed ensures that the content does not close the CDATA section.
sed 's/]]>/]]>]]&gt;<![CDATA[/g' "${failure_data_file}"
cat << EOF
]]>
</failure>
EOF
}
22 changes: 21 additions & 1 deletion hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ if [[ "${ARTIFACTS}" != "${REPO_ROOT}/_artifacts" ]]; then
ARTIFACTS=$(mktemp -d)
fi

E2E_SH_LOG_FILE="e2e-sh-log.txt"

# Redirect all output of this script additionally to a file in artifacts,
# so we can create a junit file with its content in case of general CI failures.
# This way the bash script's log can be analyzed using k8s-triage.
exec &> >(stdbuf -oL tee "${ARTIFACTS}/${E2E_SH_LOG_FILE}")

# shellcheck source=./hack/ensure-go.sh
source "${REPO_ROOT}/hack/ensure-go.sh"

Expand All @@ -56,7 +63,9 @@ on_exit() {
[[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}"

# If Boskos is being used then release the vsphere project.
[ -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}"
if [[ "${BOSKOS_HOST:-}" != "" && "${BOSKOS_RESOURCE_NAME:-}" != "" ]]; then
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}"
fi
fi

# Cleanup VSPHERE_PASSWORD from temporary artifacts directory.
Expand Down Expand Up @@ -101,6 +110,17 @@ on_exit() {
# Move all artifacts to the original artifacts location.
mv "${ARTIFACTS}"/* "${ORIGINAL_ARTIFACTS}/"
fi

# Create a junit file for running this script.
if [[ $(find "${ORIGINAL_ARTIFACTS}" -maxdepth 1 -name 'junit\.*\.xml' | wc -l) -gt 0 ]]; then
# There are junit files in artifacts so the script succeeded.
junit::createJunitReportE2Esh 0 "${ORIGINAL_ARTIFACTS}/junit.e2e-sh.xml"
else
# No junit files in artifacts so the script failed.
junit::createJunitReportE2Esh 1 "${ORIGINAL_ARTIFACTS}/junit.e2e-sh.xml" "${ORIGINAL_ARTIFACTS}/${E2E_SH_LOG_FILE}"
fi
# Always cleanup the additionally written log file used for the junit report, the same content will be in build-log.txt.
rm "${ORIGINAL_ARTIFACTS}/${E2E_SH_LOG_FILE}"
}

trap on_exit EXIT
Expand Down