Running Liquibase in Travis CI
We’re always looking for ways to give back to the Liquibase Community. We’re also big on experimenting and having fun. Combining all of that in an internal Liquibase Hackathon, my team built an example showing how to use the Liquibase Docker container to execute Liquibase commands during a Travis CI build.
Using Liquibase with Travis CI
Using Liquibase in your Travis CI builds is as easy as editing a file. The
travis.yml file is required for Travis CI to run your pipeline. General configuration properties are language and os. To pull the Liquibase Docker container, include services:docker. This is used in the before_install step to set up the container. Although global environment variables are optional, the env:global configuration is a great place to list database JDBC URL and database credentials.
Make sure you don’t pass your credentials in plain text; GitHub secrets are one way to obfuscate sensitive data. The real magic happens in the script step. This is where you pass the command line to execute as Travis CI builds.
This is what a script value looks like:
docker run --rm -v $(pwd):$(pwd) liquibase/liquibase:4.1 --classpath=$(pwd)/changelogs --url=$URL --changeLogFile=$CHANGELOGFILE --username=$USERNAME --password=$PASSWORD $OPERATION
$OPERATION are read from the env:global configuration. Note that the example uses clear text for credentials, so don’t try this at home!
Using the example repo
Want to see this work? We have created an example repository just for you! The only prerequisite is working knowledge of Git. Here’s how to use it:
- Fork and clone the
liquibase-travisci-examplerepository into a GitHub repository you own.
- Create a new Git branch for your changes.
- Add a new changeset to
example/changelogs/samplechangelog.h2.sql. For example:
--changeset your.name:4 --rollback DROP TABLE yourname; CREATE TABLE yourname ( id int primary key, name varchar(50) not null, )
- Add, commit, and push your changes to your GitHub repository.
- See your commit trigger a build in Travis CI and execute a Liquibase update!
Team CICD Plugins was led by Jake Newton and combined the mental might of Nathan Voxland, Derek Smart, Robert Reeves, Mike Olivas, Adeel Malik, Mike Runco, Dan Zentgraf, and Erzsebet Carmean.