Skip to content

Commit 47ac6d0

Browse files
fix(ci): make Linux VHD content tests resilient to illegitimate errors (#7547)
1 parent 8d2ed50 commit 47ac6d0

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

vhdbuilder/packer/test/run-test.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ set -x
128128
FULL_PATH=$(realpath $0)
129129
CDIR=$(dirname "$FULL_PATH")
130130

131-
if [ "$OS_TYPE" = "Linux" ]; then
132-
if [ -z "${ENABLE_FIPS// }" ]; then
133-
ENABLE_FIPS="false"
134-
fi
131+
if [ "${OS_TYPE,,}" = "linux" ]; then
132+
[ -z "${ENABLE_FIPS// }" ] && ENABLE_FIPS="false"
135133

136134
# If the pipeline that called this didn't set a branch, default to master.
137135
GIT_BRANCH="${GIT_BRANCH:-refs/heads/master}"
@@ -158,14 +156,20 @@ if [ "$OS_TYPE" = "Linux" ]; then
158156
# ]
159157
# We have extract the message field from the json, and get the errors outputted to stderr + remove \n
160158
errMsg=$(echo -e "$(echo "$ret" | jq ".value[] | .message" | grep -oP '(?<=stderr]).*(?=\\n")')")
161-
if [ "$errMsg" != '' ]; then
159+
# Test failures as specifically written to stderr in the form of "testname:Error: message", thus we specifically check to see if there was at least
160+
# one test failure via the following regex comparison on errMsg. Otherwise, transient errors not produced by a test case
161+
# (such as "sudo: unable to resolve host vhd-test-vm: Name or service not known") will cause the entire run-test step to fail.
162+
# shellcheck disable=SC3010
163+
if [[ "$errMsg" == *":Error:"* ]]; then
162164
echo "Tests failed."
163165
echo "Extracted error message: $errMsg"
164166
echo "Test output is: "
165167
echo "$ret"
166168
exit 1
167169
fi
168-
else
170+
fi
171+
172+
if [ "${OS_TYPE,,}" = "windows" ]; then
169173
SCRIPT_PATH="$CDIR/$WIN_SCRIPT_PATH"
170174
echo "Run $SCRIPT_PATH"
171175
ret=$(az vm run-command invoke --command-id RunPowerShellScript \

0 commit comments

Comments
 (0)