Skip to content
Snippets Groups Projects
Commit cacfb073 authored by Bartek Wrona's avatar Bartek Wrona
Browse files

Merge branch '112-ci-pipeline-should-exit-with-error-when-script' into 'develop'

Resolve "CI pipeline should exit with error, when script cannot recreate existing database"

See merge request !397
parents 3274323f 26c16e67
No related branches found
No related tags found
2 merge requests!456Release candidate v1 24,!397Resolve "CI pipeline should exit with error, when script cannot recreate existing database"
......@@ -49,6 +49,7 @@ stages:
- echo "${CI_RUNNER_ID}" > hive-sync-runner-id.txt
- ./scripts/ci/wait-for-postgres.sh "$RUNNER_POSTGRES_HOST" "$RUNNER_POSTGRES_PORT"
- export POSTGRES_MAJOR_VERSION=$(./scripts/ci/get-postgres-version.sh)
- ./scripts/ci/drop-db.sh
- ./scripts/ci/create-db.sh
- ./scripts/ci/hive-sync.sh
- ./scripts/ci/collect-db-stats.sh
......
......@@ -28,10 +28,6 @@ BEGIN
END
\$$;
-- We drop database to enable retry of CI job.
\echo Dropping database ${HIVEMIND_DB_NAME}
DROP DATABASE IF EXISTS ${HIVEMIND_DB_NAME};
\echo Creating database ${HIVEMIND_DB_NAME}
CREATE DATABASE ${HIVEMIND_DB_NAME} TEMPLATE ${TEMPLATE}
OWNER ${RUNNER_POSTGRES_APP_USER};
......
#!/bin/bash
# set -euo pipefail
drop_db() {
echo "Dropping database ${HIVEMIND_DB_NAME}"
PGPASSWORD=${RUNNER_POSTGRES_ADMIN_USER_PASSWORD} dropdb \
--if-exists \
--username "${RUNNER_POSTGRES_ADMIN_USER}" \
--host ${RUNNER_POSTGRES_HOST} \
--port ${RUNNER_POSTGRES_PORT} \
${HIVEMIND_DB_NAME}
RESULT=$?
if [[ ! $RESULT -eq 0 ]]; then
cat << EOF
ERROR: cannot drop database ${HIVEMIND_DB_NAME}.
Most often the reason is that database is used by other sessions.
This can happen on Gitlab CI server, when jobs are picked by multiple,
concurrent runners and database name is not unique on subsequent
pipelines. If this is the case, please cancel any pending pipelines
running for your branch or for your merge request, or wait until they
finish. Then retry this pipeline.
Exiting with error at this moment.
EOF
exit $RESULT
else
echo "Database ${HIVEMIND_DB_NAME} has been dropped successfully"
fi
}
drop_db
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment