Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Travis-CI test for MongoDB connectivity before script
# This script will test for MongoDB connectivity.
# If MongoDB is available then it continues else it tries X times then fails.
# Use: Add this to your `before_script` option
- |
echo "Testing MongoDB connection...";tries=4;
while [ $i -lt $tries ]; do fail=$(mongo --eval db 2>&1 >/dev/null | grep "connect failed");
if [ "$fail" ] && [ $[ $i+1 ] -eq $tries ] ; then echo "Error: Could not connect to mongodb"; exit 1;
elif [ "$fail" ]; then sleep 3; i=$[ $i+1 ];
else echo "OK"; i=$tries; fi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.