Mysql database contents available on service creation but empty when tests are ran

Hi All,

I’ve been trying to run some tests which involve a mysql service that runs a database import. The import seems to run correctly but for some reason when running the tests, the database exists but it has no contents (no tables at all). I’m not sure why that is and wondered if anyone had any idea why that may be.
It’s almost like the database is wiped by the time the tests have been run but the actual database is still there, just empty.

I’ve included my gitlab-ci.yml file below but if any further information is needed, please let me know.


I’m running this on

image: maven:3-jdk-8

# Mysql server needed to run tests
  - mysql:latest

  # Configure mysql environment variables (
  MYSQL_DATABASE: "db0001"

  - connect
  - test
  - build

  script: "mvn verify"

  script: "mvn install -B"

  image: mysql
    - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE" < database/skeleton.sql
    - echo "select count(*) from $MYSQL_DATABASE.nameservers;" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE"
    - echo "show databases;" | mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql "$MYSQL_DATABASE"

Hi, I just wondered if anyone had any ideas. Looking at this again and have not managed to spot what the problem is. Thanks

Hey there,

I believe the issue is that the global service key you specified is actually doing the same thing as
default: service:.

The service is actually recreated in each job that you have. It doesn’t remain across stages/jobs in a pipeline.

See documentation here referencing individual “jobs”.

For testing, I recommend building a test MySQL container with the data you need, push that image to a registry, and then use that image as a service in your pipelines.