Redgate 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 Toggle source code

          1. #Flyway Version to Use - Check here for latest version information - https://documentation.red-gate.com/fd/command-line-184127404.html
          2.  
          3. $flywayVersion = '10.8.1'
          4.  
          5. #Flyway URL to download CLI
          6.  
          7. $Url = "https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/$flywayVersion/flyway-commandline-$flywayVersion-windows-x64.zip"
          8.  
          9. #Insert path for downloaded files
          10.  
          11. $DownloadZipFile = "C:\FlywayCLI\" + $(Split-Path -Path $Url -Leaf)
          12.  
          13. #Assign location for Flyway to extracted to
          14.  
          15. $ExtractPath = "C:\FlywayCLI\"
          16.  
          17. #SilentlyContinue informs PowerShell to download the CLI without a progress bar. This often drastically improves the download time.
          18.  
          19. $ProgressPreference = 'SilentlyContinue'
          20.  
          21. if (Test-Path $ExtractPath) {
          22. Write-Host "Folder Exists"
          23.  
          24. }
          25. else
          26. {
          27. #PowerShell Create directory if not exists
          28. New-Item $ExtractPath -ItemType Directory
          29. Write-Host "Folder Created successfully"
          30. }
          31.  
          32. # Download the CLI to the desired location
          33.  
          34. Invoke-WebRequest -Uri $Url -OutFile $DownloadZipFile
          35.  
          36. # Extract the CLI to the desired location
          37.  
          38. $ExtractShell = New-Object -ComObject Shell.Application
          39.  
          40. $ExtractFiles = $ExtractShell.Namespace($DownloadZipFile).Items()
          41.  
          42. $ExtractShell.NameSpace($ExtractPath).CopyHere($ExtractFiles)
          43. Start-Process $ExtractPath
          44.  
          45. # Update PATH Variable with Flyway CLI - Azure DevOps #
          46.  
          47. # echo "##vso[task.setvariable variable=path]$(PATH);C:\FlywayCLI\flyway-$flywayVersion"
          48.  
          49. # Update PATH variable with Flyway CLI - Generic - Comment above and uncomment below to take affect #
          50.  
          51. [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 Toggle source code

          1. 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?