Team City
Published 08 June 2023
Setup:
- Install the Flyway CLI on your agents unless you are using Docker (Installers).
- Be able to connect to a build db from the agent.
Example:
Use the command line runner to execute Flyway commands.
Step 1: Setup a Build Configuration
- Navigate to your project in TeamCity and click on "Create build configuration".
- Enter a name for the build configuration, for example, "Flyway Migrations".
- Set up your version control settings to point to the repository where your flyway migration scripts are.
Step 2: Add Build Step(s)
Click on "Add build step".
Choose "Command Line" as the runner type.
In the "Custom script" field, enter the command to run Flyway migrations. This will look something like this if you're using the Flyway command line tool:
flyway migrate -url=%db_url% -user=%db_user% -password=%db_password% -locations=filesystem:<path_to_migrations>
Or like this if you're using the Flyway Docker image
docker run --rm -v /path/to/migrations:/<folder>/<migrations/folder> flyway/flyway migrate -url=%db_url% -user=%db_user% -password=%db_password%
Optional: Use the clean migrate commands together to build the CI database from scratch every time.
Step 4: Set up your database credentials as parameters
- Navigate to the "Parameters" area of your build configuration.
- Add the following 3 database credentials with the value's hidden so they are not in plain text
- db_url
- db_user
- db_password
Step 3: Triggering the Build
- Navigate to the Triggers page of your build configuration.
- Add a new trigger, choosing the type that fits your process (for instance, a VCS trigger if you want the build to run on every commit).
Next steps:
- You may want to setup database unit tests or code analysis.
- You'll want to use the output of this build (an artifact) in a Release Management system to deploy the database changes to downstream environments (e.g., Test > QAT > Staging > Prod).