Reputation: 12896
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.
flyway:
image: boxfuse/flyway:5.2.4
command: -url=jdbc:mariadb://mariadb_service -schemas=$${MYSQL_DATABASE} -table=schema_version -connectRetries=60 info
volumes:
- ./db/migration:/flyway/sql
depends_on:
- 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.
docker-compose.yml
in my Jenkinsfile
would the corresponding stage fail upon errors during the migration? Speaking, would Jenkins notice that error?Jenkinsfile
Upvotes: 1
Views: 2965
Reputation: 5931
You can use Jenkins built-in support for Docker. Then your pipeline script may contain the stage
stage('Apply DB changes') {
agent {
docker {
image 'boxfuse/flyway:5.2.4'
args '-v ./db/migration:/flyway/sql --entrypoint=\'\''
}
}
steps {
sh "/flyway/flyway -url=jdbc:mariadb://mariadb_service -schemas=${MYSQL_DATABASE} -table=schema_version -connectRetries=60 info"
}
}
This way the steps
will be executed within temporary Docker container created by Jenkins agent
from boxfuse/flyway
image. If the command fails the entire stage will fail as well.
Upvotes: 4