6.2 Deploying Your Changes via Azure DevOps
Published 09 September 2024
Now that you've committed your migration scripts to the hosted repository, it's time to set up continuous integration and deployment (CI/CD) using Azure DevOps. This setup allows your database changes to be automatically applied across all environments, ensuring a smooth deployment process.
Tip: These YAML pipelines read from the Flyway project to know the locations of the target databases! When provisioning your databases, we updated the connections in Flyway Desktop to point to the newly created databases. If the pipeline encounters issues finding a database, double-check that your Flyway project has the correct and working connections to these databases. Refer back to Provisioning your Databases for more details and troubleshooting tips.
Step 1: Set Up an Azure DevOps Project (If Not Already Done)
If you haven't already set up an Azure DevOps project or imported your repository, head back to the Getting Your Repository Ready steps to ensure everything is configured properly.
Step 2: Setting Up an Azure DevOps Agent
- Provision an Agent:
- To run the pipeline, you need an Azure DevOps Agent that can access the databases you provisioned earlier. The Agent must have connectivity to these databases, whether they are on localhost, a VM, or another server.
- For more details on setting up an agent, refer to the official Azure DevOps agent documentation.
Step 3: Authenticating with Flyway (Creating a Personal Access Token)
Set Up a Personal Access Token (Click here for more details)
A valid Flyway License is required in order to authenticate Flyway within a pipeline. The most secure and industry standard way of doing this is through setting up a Personal Access token, linked to your Redgate Portal account.
- Step 1: Navigate to https://identityprovider.red-gate.com/personaltokens
- Step 2: Login with your Redgate Portal account
- This should link to the Redgate Account used when starting your trial within Flyway Desktop.
- If you're still unaware which account to use, navigate back to Flyway Desktop and validate which account was used or sign up for a new trial.
- Step 3: Click '+ New Token' to create a new Personal Access Token
- Ensure you save this somewhere, like a password manager, as there's no method of seeing the token again in future.
- Treat this token just like any other secure password you use. If the token is lost, or compromised, simply choose to revoke the token and create a new one.
- Step 4: Navigate to the Redgate Portal website (Where you can see all licenses linked to your account) - https://portal.red-gate.com/licenses
- Step 5: Select Flyway Enterprise from the list (You may need to select 'Licenses on the left hand side menu to see it)
- If the Flyway Enterprise trial was started through Flyway Desktop, your Email Address will automatically have been allocated to the license 'Flyway Desktop Enterprise'.
- Step 6: Ensure the license is allocated to your email address. To do this, click '+ Allocate' > Enter your email address > Click Add User'
Note - Flyway CLI License Keys (Which start FL01) are still valid and can be used within pipelines. However, these will be deprecated in time, therefore Redgate recommends moving to PATs as described above. Reach out to the AutoPilot team at flywayap@red-gate.com if you need any further details
Step 4: Setup the pipeline
Create the Pipeline:
- In Azure DevOps, go to Pipelines and click New Pipeline.
- Choose Azure Repos Git and select the repository you created (by default, it’s named Flyway AutoPilot).
- Select Existing Azure Pipelines YAML File and choose the YAML file correct for you, you will find several YAML scripts clearly labeled with an OS suffix based on the operating system of your agent (e.g.,
windows.yml
,linux.yml
)..
- In Azure DevOps, go to Pipelines and click New Pipeline.
Edit the Azure DevOps YAML Pipeline:
- Using the Azure DevOps YAML editor, it's necessary to review and configure the connection details Flyway will use. The pipeline has been designed with simplicity at it's heart, however below are some parameters that should be checked
Key Parameters to Review:
- Connection Strings:
- Your pipeline will use the 'Environment' parameters to pass connection strings from your Flyway Desktop project. This means, no need to manually enter database URLs — just ensure that the Flyway environment placeholders are accurate and have been pushed to your repository.
- The workflows are pre-configured to use the 'Environment' details configured through Flyway Desktop, stored in the flyway.toml project file. Therefore, if necessary use the 'Migration Scripts' tab in Flyway Desktop to validate these by clicking 'Manage target databases'.
- This was done in an earlier section, however head to Provisioning Your Databases for more details.
- Securing your Personal Access Token
- In the YAML file, you'll see two variables for FLYWAY_EMAIL & FLYWAY_TOKEN, both of which are pointing to secure variables that don't yet exist. Therefore, to keep these values secure, we must create two secure variables by selecting the variables button in the top right hand corner.
- In the YAML file, you'll see two variables for FLYWAY_EMAIL & FLYWAY_TOKEN, both of which are pointing to secure variables that don't yet exist. Therefore, to keep these values secure, we must create two secure variables by selecting the variables button in the top right hand corner.
- Optional: Flyway License Key (Deprecated):
- In the YAML file, you'll also see a placeholder for the
FLYWAY_LICENSE_KEY
. This is the soon to be legacy method for Flyway CLI authentication. Should you wish to use this, simply add your Flyway CLI key to the FLYWAY_LICENSE_KEY variable, ensuring it is first uncommented (I.e remove the # at the beginning of the string)
SQL Authentication (if needed)
If you're using SQL Authentication instead of Windows Authentication, you will need to provide the Username and Password in the YAML file. Ensure the username and password is either entered as plaintext, or setup as a secure variable, referenced just as shown in the illustration below: - In the YAML file, you'll also see a placeholder for the
Security Tip: Whilst you can put secure values inline for testing, we strongly recommend moving any secure information into a secure variable or variable group for production implementation. Referencing them accordingly, see the FLYWAY_EMAIL example in step 2b.
Step 5: Run the Pipeline
Once the pipeline definition is setup, simply click Save & Run in the top right hand side box.