2019-02-26 11:59:53 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
function fail() {
|
|
|
|
local message="$1"
|
|
|
|
local returnCode=${2:-1}
|
|
|
|
echo "[ERROR] ${message}" >&2
|
2019-03-01 15:47:48 +02:00
|
|
|
exit "${returnCode}"
|
2019-03-01 14:27:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function notify() {
|
|
|
|
|
|
|
|
local state=${1}
|
|
|
|
local description=${2}
|
|
|
|
local hash=${3}
|
|
|
|
|
|
|
|
echo "[INFO] Notifying about state \"${state}\" for commit \"${hash}\"."
|
|
|
|
|
|
|
|
curl -X POST \
|
|
|
|
--fail \
|
|
|
|
--silent \
|
|
|
|
--output /dev/null \
|
|
|
|
--data "{\"state\": \"${state}\", \"target_url\": \"${TRAVIS_BUILD_WEB_URL}\", \"description\": \"${description}\", \"context\": \"integration-tests\"}" \
|
|
|
|
--user "${INTEGRATION_TEST_VOTING_USER}:${INTEGRATION_TEST_VOTING_TOKEN}" \
|
|
|
|
"https://api.github.com/repos/SAP/jenkins-library/statuses/${hash}" || fail "Cannot send notification. curl return code: $?"
|
|
|
|
}
|
|
|
|
|
2019-03-01 16:14:47 +02:00
|
|
|
function cleanup() {
|
|
|
|
[ -z "${notificationThreadPid}" ] || kill -PIPE "${notificationThreadPid}" &>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2019-02-28 09:07:18 +02:00
|
|
|
#
|
|
|
|
# In case the build is performed for a pull request TRAVIS_COMMIT is a merge
|
|
|
|
# commit between the base branch and the PR branch HEAD. That commit is actually built.
|
|
|
|
# But for notifying about a build status we need the commit which is currenty
|
|
|
|
# the HEAD of the PR branch.
|
|
|
|
#
|
|
|
|
# In case the build is performed for a simple branch (not associated with a PR)
|
|
|
|
# In this case there is no merge commit between any base branch and HEAD of a PR branch.
|
|
|
|
# The commit which we need for notifying about a build status is in this case simply
|
|
|
|
# TRAVIS_COMMIT itself.
|
|
|
|
#
|
|
|
|
COMMIT_HASH_FOR_STATUS_NOTIFICATIONS="${TRAVIS_PULL_REQUEST_SHA}"
|
|
|
|
[ -z "${COMMIT_HASH_FOR_STATUS_NOTIFICATIONS}" ] && COMMIT_HASH_FOR_STATUS_NOTIFICATIONS="${TRAVIS_COMMIT}"
|
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
notify "pending" "Integration tests in progress." "${COMMIT_HASH_FOR_STATUS_NOTIFICATIONS}"
|
2019-02-27 16:43:12 +02:00
|
|
|
|
2019-02-26 14:36:50 +02:00
|
|
|
WORKSPACES_ROOT=workspaces
|
|
|
|
[ -e "${WORKSPACES_ROOT}" ] && rm -rf ${WORKSPACES_ROOT}
|
2019-02-26 11:59:53 +02:00
|
|
|
|
2019-02-27 10:18:02 +02:00
|
|
|
TEST_CASES=$(find testCases -name '*.yml')
|
2019-02-26 17:10:13 +02:00
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
# This auxiliar thread is needed in order to produce some output while the
|
|
|
|
# test are running. Otherwise the job will be canceled after 10 minutes without
|
|
|
|
# output.
|
2019-02-27 14:08:12 +02:00
|
|
|
while true; do sleep 10; echo "[INFO] Integration tests still running."; done &
|
|
|
|
notificationThreadPid=$!
|
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
declare -a processes
|
2019-02-26 17:10:13 +02:00
|
|
|
i=0
|
|
|
|
for f in ${TEST_CASES}
|
2019-02-26 11:59:53 +02:00
|
|
|
do
|
2019-02-26 17:51:47 +02:00
|
|
|
testCase=$(basename "${f%.*}")
|
|
|
|
area=$(dirname "${f#*/}")
|
2019-02-26 17:47:31 +02:00
|
|
|
echo "[INFO] Running test case \"${testCase}\" in area \"${area}\"."
|
|
|
|
TEST_CASE_ROOT="${WORKSPACES_ROOT}/${area}/${testCase}"
|
|
|
|
[ -e "${TEST_CASE_ROOT}" ] && rm -rf "${TEST_CASE_ROOT}"
|
2019-03-01 14:27:33 +02:00
|
|
|
mkdir -p "${TEST_CASE_ROOT}" || fail "Cannot create test case root director for test case \"${testCase}\"." 1
|
2019-02-26 17:51:47 +02:00
|
|
|
source ./runTest.sh "${testCase}" "${TEST_CASE_ROOT}" &> "${TEST_CASE_ROOT}/log.txt" &
|
2019-02-26 17:47:31 +02:00
|
|
|
pid=$!
|
2019-03-01 14:35:14 +02:00
|
|
|
processes[$i]="${area}/${testCase}:${pid}"
|
2019-02-26 17:47:31 +02:00
|
|
|
echo "[INFO] Test case \"${testCase}\" in area \"${area}\" launched. (PID: \"${pid}\")."
|
|
|
|
let i=i+1
|
2019-02-26 17:10:13 +02:00
|
|
|
done
|
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
[ "${i}" == 0 ] && fail "No tests has been executed." 1
|
2019-02-27 09:56:09 +02:00
|
|
|
|
2019-02-26 17:10:13 +02:00
|
|
|
#
|
|
|
|
# wait for the test cases and cat the log
|
|
|
|
for p in "${processes[@]}"
|
|
|
|
do
|
2019-03-01 15:47:48 +02:00
|
|
|
area=$(dirname "${p%:*}")
|
|
|
|
testCase=$(basename "${p%:*}")
|
|
|
|
processId="${p#*:}"
|
2019-03-01 14:35:14 +02:00
|
|
|
echo "[INFO] Waiting for test case \"${testCase}\" in area \"${area}\" (PID: \"${processId}\")."
|
2019-02-26 17:51:47 +02:00
|
|
|
wait "${processId}"
|
2019-03-01 14:35:14 +02:00
|
|
|
echo "[INFO] Test case \"${testCase}\" in area \"${area}\" finished (PID: \"${processId}\")."
|
2019-02-26 17:10:13 +02:00
|
|
|
done
|
2019-02-26 14:36:50 +02:00
|
|
|
|
2019-03-01 16:14:47 +02:00
|
|
|
kill -PIPE "${notificationThreadPid}" &>/dev/null && notificationThreadPid=""
|
2019-02-27 14:08:12 +02:00
|
|
|
|
2019-02-27 14:09:06 +02:00
|
|
|
#
|
|
|
|
# provide the logs
|
|
|
|
for p in "${processes[@]}"
|
|
|
|
do
|
2019-03-01 15:47:48 +02:00
|
|
|
area=$(dirname "${p%:*}")
|
|
|
|
testCase=$(basename "${p%:*}")
|
2019-02-27 14:09:06 +02:00
|
|
|
echo "[INFO] === START === Logs for test case \"${testCase}\" ===."
|
|
|
|
cat "${TEST_CASE_ROOT}/log.txt"
|
|
|
|
echo "[INFO] === END === Logs for test case \"${testCase}\" ===."
|
|
|
|
done
|
|
|
|
|
2019-02-26 17:10:13 +02:00
|
|
|
#
|
|
|
|
# list test case status
|
|
|
|
echo "[INFO] Build status:"
|
|
|
|
failure="false"
|
|
|
|
for p in "${processes[@]}"
|
|
|
|
do
|
2019-02-26 17:47:31 +02:00
|
|
|
status="UNDEFINED"
|
2019-03-01 15:47:48 +02:00
|
|
|
area=$(dirname "${p%:*}")
|
|
|
|
testCase=$(basename "${p%:*}")
|
2019-03-01 14:35:14 +02:00
|
|
|
TEST_CASE_ROOT="${WORKSPACES_ROOT}/${area}/${testCase}"
|
2019-02-26 17:47:31 +02:00
|
|
|
if [ -f "${TEST_CASE_ROOT}/SUCCESS" ]
|
|
|
|
then
|
|
|
|
status="SUCCESS"
|
|
|
|
else
|
|
|
|
status="FAILURE"
|
|
|
|
failure="true"
|
|
|
|
fi
|
2019-03-01 14:27:33 +02:00
|
|
|
printf "[INFO] %-30s: %s\n" "${testCase}" "${status}"
|
2019-02-26 11:59:53 +02:00
|
|
|
done
|
2019-02-26 17:10:13 +02:00
|
|
|
|
2019-02-27 16:43:12 +02:00
|
|
|
STATUS_DESCRIPTION="The integration tests failed."
|
|
|
|
STATUS_STATE="failure"
|
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
if [ "${failure}" == "false" ]
|
2019-02-26 17:10:13 +02:00
|
|
|
then
|
2019-02-27 16:43:12 +02:00
|
|
|
STATUS_DESCRIPTION="The integration tests succeeded."
|
|
|
|
STATUS_STATE="success"
|
2019-02-26 17:10:13 +02:00
|
|
|
fi
|
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
notify "${STATUS_STATE}" "${STATUS_DESCRIPTION}" "${COMMIT_HASH_FOR_STATUS_NOTIFICATIONS}"
|
2019-02-27 16:43:12 +02:00
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
[ "${failure}" != "false" ] && fail "Integration tests failed." 1
|
2019-02-27 16:43:12 +02:00
|
|
|
|
2019-03-01 14:27:33 +02:00
|
|
|
echo "[INFO] Integration tests succeeded."
|
2019-02-26 17:10:13 +02:00
|
|
|
exit 0
|