Automate Flyway migration with Docker and Jenkins

I’d like to automate the Flyway migrations for our MariaDB database. For testing purposes I added the following service to my docker-compose.yml running only the info command.

    image: boxfuse/flyway:5.2.4
    command: -url=jdbc:mariadb://mariadb_service -schemas=$${MYSQL_DATABASE} -table=schema_version -connectRetries=60 info
      - ./db/migration:/flyway/sql
      - mariadb_service

This seems to be working, i.e. I can see the output of info.

Now I’d like to take this idea one step further and integrate this into our Jenkins build pipeline. This is where I get stuck.

  1. If I deployed the Docker stack with the above docker-compose.yml in my Jenkinsfile would the corresponding stage fail upon errors during the migration? Speaking, would Jenkins notice that error?
  2. If this is not true how can I integrate the Flyway migration in my Jenkins pipeline? I found that there is a Flyway Runner plugin but I didn’t see if this can connect to a database in a Docker stack deployed by the Jenkinsfile

Source: StackOverflow