Team City


Setup:

  1. Install the Flyway CLI on your agents unless you are using Docker (Installers).
  2. 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

  1. Navigate to your project in TeamCity and click on "Create build configuration".
  2. Enter a name for the build configuration, for example, "Flyway Migrations".
  3. Set up your version control settings to point to the repository where your flyway migration scripts are.

Step 2: Add Build Step(s)

  1. Click on "Add build step".

  2. Choose "Command Line" as the runner type.

  3. 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

  1. Navigate to the "Parameters" area of your build configuration.
  2. Add the following 3 database credentials with the value's hidden so they are not in plain text
    1. db_url
    2. db_user
    3. db_password

Step 3: Triggering the Build

  1. Navigate to the Triggers page of your build configuration.
  2. 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).



Didn't find what you were looking for?