Flyway

Using Flyway on your CI/CD Agents

In order to use Flyway to migrate your databases as part of an automated CI/CD pipeline, you need to be able to access Flyway on your CI/CD agents.  There are a few ways to do this:


  1. Use Docker.  This way, you can just pull the latest version or a tagged version into your pipeline when it runs.  There's nothing to install/maintain.

  2. Install the Flyway command line by downloading it and unzipping it to a location on the agent (e.g., C:\Flyway).  Make sure your PATH environment variable is set to use this location.  When you upgrade Flyway, just unzip the file and replace the contents of the existing folder.  This way your path still has the correct reference.
    1. Windows
      1. The below PowerShell script example has been designed for use at the start of a Pipeline, where the agent requires Flyway to be installed  (Change the flyway version number as required:
        1. Windows - Install Flyway CLI Script

          #Flyway Version to Use - Check here for latest version information - https://documentation.red-gate.com/fd/command-line-184127404.html
          
          $flywayVersion = '10.8.1'
          
          #Flyway URL to download CLI
          
          $Url = "https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/$flywayVersion/flyway-commandline-$flywayVersion-windows-x64.zip"
          
          #Insert path for downloaded files
          
          $DownloadZipFile = "C:\FlywayCLI\" + $(Split-Path -Path $Url -Leaf)
          
          #Assign location for Flyway to extracted to
          
          $ExtractPath = "C:\FlywayCLI\"
          
          #SilentlyContinue informs PowerShell to download the CLI without a progress bar. This often drastically improves the download time.
          
          $ProgressPreference = 'SilentlyContinue'
          
          if (Test-Path $ExtractPath) {
             
              Write-Host "Folder Exists"
          
          }
          else
          {
            
              #PowerShell Create directory if not exists
              New-Item $ExtractPath -ItemType Directory
              Write-Host "Folder Created successfully"
          }
          
          # Download the CLI to the desired location
          
          Invoke-WebRequest -Uri $Url -OutFile $DownloadZipFile
          
          # Extract the CLI to the desired location
          
          $ExtractShell = New-Object -ComObject Shell.Application
          
          $ExtractFiles = $ExtractShell.Namespace($DownloadZipFile).Items()
          
          $ExtractShell.NameSpace($ExtractPath).CopyHere($ExtractFiles) 
          Start-Process $ExtractPath
          
          # Update PATH Variable with Flyway CLI - Azure DevOps #
          
          # echo "##vso[task.setvariable variable=path]$(PATH);C:\FlywayCLI\flyway-$flywayVersion"
          
          # Update PATH variable with Flyway CLI - Generic - Comment above and uncomment below to take affect #
          
          [Environment]::SetEnvironmentVariable("PATH", $Env:PATH + ";${ExtractPath}flyway-$flywayVersion", [EnvironmentVariableTarget]::Machine)
    2. Linux
      1. The below BASH script example has been designed for use at the start of a Pipeline, where the Linux agent requires Flyway to be installed (Change the flyway version number as required):
        1. Linux - Installing Flyway CLI Script

          wget -qO- https://download.red-gate.com/maven/release/com/redgate/flyway/flyway-commandline/10.8.1/flyway-commandline-10.8.1-linux-x64.tar.gz | tar -xvz && sudo ln -s `pwd`/flyway-10.8.1/flyway /usr/local/bin
  3. Commit the unzipped flyway command line files into your version control system.  Your CI/CD agents can checkout the repository with the necessary flyway files to execute the flyway commands from there.  When upgrading, just commit the latest flyway into your repository and it will be used in future pipelines.

  4. Use Chocolatey or another package management system.

Didn't find what you were looking for?