Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated sample pipeline using environments #8

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Azure-Templatized-YML-Pipeline-Environments/EnvInstructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# How to wire pipeline variables to environments
## Changes to vars.yml
Remove the username and password variables from the Flyway command. These will be brought in later with the environments
## Changes to yaml files (deploy.yml, build.yml)
Map pipeline variables to env variables in each flyway script step
![image](https://github.com/kathikelRG/Flyway-Sample-Pipelines/assets/148022047/f36e5012-bd06-46ad-9dcc-64f92e110a7c)

Remove Url, check.buildUrl, check.user, check.password from flyway commands. Replace with environment and check.buildEnvironment
![image](https://github.com/kathikelRG/Flyway-Sample-Pipelines/assets/148022047/d8d812ad-6b87-4e74-941e-7d69c8208f5b)

## Changes to flyway.toml
Add an environment section for each stage. Map env variables in the section. Important! Envrionment section name is case sensitive when adding to command.
![image](https://github.com/kathikelRG/Flyway-Sample-Pipelines/assets/148022047/29d694e1-15b5-4e2d-b195-7939b3045701)

Note that the environments with variables cannot be opened in Flyway Desktop. Flyway Desktop will work if opening a target on the Migrations tab with hard-coded values but not with the variables.
![image](https://github.com/kathikelRG/Flyway-Sample-Pipelines/assets/148022047/c995cf32-b5c9-4d93-ae8e-c15605d39c3e)

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
param ($deploymentTargetsList, $baselineVersion, $flywayLicenseKey, $workingDirectory)

write-host "deploymentTargetsList: $deploymentTargetsList"

Import-csv -path $deploymentTargetsList |
Foreach-object {

$currentJDBC = $_.JDBCString
$deployment = "flyway migrate -outOfOrder='true' -baselineOnMigrate='true' -errorOverrides='S0001:0:I'- -baselineVersion=" + $baselineVersion + " -licenseKey=" + $flywayLicenseKey + " -configFiles=" + $workingDirectory + "\flyway.conf" + " -locations=filesystem:" + $workingDirectory + '\migrations' + " -url='" + $currentJDBC + "'"
write-host "flywayCommand:" + $deployment
write-host "deploying to: $currentJDBC"
Invoke-Expression $deployment
}
47 changes: 47 additions & 0 deletions Azure-Templatized-YML-Pipeline-Environments/deploy-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# NOTE: This pipeline depends on the following variable groups:

# Name of variable group Keys inside variable group
# ---------------------- --------------------------
# redgate_global_vars FLYWAY_LICENSE_KEY
# redgate_pipeline_vars BASELINE_VERSION, FIRST_UNDO_SCRIPT, AGENT_POOL
# redgate_target_database_credentials userName, password, target_database_JDBC, databaseName, check_JDBC, check_userName, check_password

# redgate_build_credentials userName, password, target_database_JDBC, databaseName

# Every target database will need its own variable group, which is referenced in a YML deployment script
# The default is to include the agent pools inside a pipeline definition, to accommodate multiple agent pools.
# If appropriate, the agent pool definition could be moved to the global variable group (or a target specific variable group)

# PARELLELISM
# Pay close attention to the "dependsOn" flag - this determines which block follows each other.
# It's possible to parallelize dpelyments by using multiple agent pools and the "dependsOn" flag.

name: ADO-self-hosted-pipeline-templatized

trigger:
branches:
include:
- development
paths:
include:
- migrations/*

# Move the templates to their own repository for greater control and lack of repitition across projects (DRY)
# They can be included in the same repository if preferred: templates/vars.yml would work for the file below
resources:
repositories:
- repository: templates
type: git
name: templates

variables:
- template: vars.yml@templates # templates/vars.yml if kept in same repository

stages:
- template: build.yml@templates # templates/build.yml if kept in same repository
parameters:
stage: Build
displayName: Deploy Build
cleanBuildDB: true # Optional flag. Defaults to false
targetCredentials: redgate_build_credentials
pipelineParameters: redgate_pipeline_vars
45 changes: 45 additions & 0 deletions Azure-Templatized-YML-Pipeline-Environments/deploy-cherrypick.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: cherrypick-pipeline

# This pipeline will go through the build process and generate all artifacts as normal, it just
# requires a manual trigger and inputting a comma-separated list of version scripts.

trigger: none

resources:
repositories:
- repository: templates
type: git
name: templates

parameters:
- name: cherryPickVersions
displayName: 'Scripts To Undo: Comma Separated List Of Full Version Numbers'
default: ''
type: string

variables:
# This is the relative path to the migrations folder in your project, such as:
# $(System.DefaultWorkingDirectory)\project
# The default is to have the migrations folder in the same directory as the yml file
WORKING_DIRECTORY: $(System.DefaultWorkingDirectory)
FLYWAY: 'flyway -user="$(userName)" -password="$(password)" -baselineOnMigrate=true -errorOverrides=S0001:0:I- -baselineVersion=$(BASELINE_VERSION) -licenseKey=$(FLYWAY_LICENSE_KEY) -configFiles="$(WORKING_DIRECTORY)\flyway.conf"'
BUILD_NAME: 'Repository-Snapshot'
RELEASE_PREVIEW: 'Release-Preview.sql'
DRIFT_AND_CHANGE_REPORT: 'Drift-And-Change-Report.html'
DRIFT_AND_CHANGE_REPORT_DISPLAY_NAME: 'Drift And Change Report'
cherryPickVersions: ${{parameters.cherryPickVersions}}

stages:

- template: cherrypick.yml@templates
parameters:
stage: Test
displayName: Deploy Test
pauseForCodeReview: false
failReleaseIfDriftDetected: false
generateDriftAndChangeReport: true
staticCodeAnalysis: false
targetCredentials: redgate_test_credentials
pipelineParameters: redgate_pipeline_vars
cherryPickVersions: ${{ variables.cherryPickVersions }}

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# NOTE: This pipeline depends on the following variable groups:

# Name of variable group Keys inside variable group
# ---------------------- --------------------------
# redgate_global_vars FLYWAY_LICENSE_KEY
# redgate_pipeline_vars BASELINE_VERSION, FIRST_UNDO_SCRIPT, AGENT_POOL
# redgate_target_database_credentials userName, password, target_database_JDBC, databaseName, check_JDBC, check_userName, check_password

# redgate_build_credentials userName, password, target_database_JDBC, databaseName

# Every target database will need its own variable group, which is referenced in a YML deployment script
# The default is to include the agent pools inside a pipeline definition, to accommodate multiple agent pools.
# If appropriate, the agent pool definition could be moved to the global variable group (or a target specific variable group)

# PARELLELISM
# Pay close attention to the "dependsOn" flag - this determines which block follows each other.
# It's possible to parallelize dpelyments by using multiple agent pools and the "dependsOn" flag.

name: ADO-self-hosted-pipeline-templatized

# trigger: none
trigger:
branches:
include:
- master
paths:
include:
- migrations/*

# Move the templates to their own repository for greater control and lack of repitition across projects (DRY)
# They can be included in the same repository if preferred: templates/vars.yml would work for the file below
resources:
repositories:
- repository: templates
type: git
name: templates

variables:
- template: csv-vars.yml@templates # templates/vars.yml if kept in same repository

stages:
# - template: build.yml@templates # templates/build.yml if kept in same repository
# parameters:
# stage: Build
# displayName: Deploy Build
# executeBuild: false
# targetCredentials: northwind_build_credentials
# pipelineParameters: northwind_pipeline_vars

- template: csv-deploy.yml@templates # templates/deploy.yml if kept in same repository
parameters:
stage: Batch1
displayName: Deploy Batch1
# dependsOn: Build
baselineVersion: $(BASELINE_VERSION)
flywayLicenseKey: $(FLYWAY_LICENSE_KEY)
workingDirectory: $(WORKING_DIRECTORY)
deploymentTargetsList: deployment-targets-batch-1.csv
pipelineParameters: northwind_pipeline_vars

- template: csv-deploy.yml@templates # templates/deploy.yml if kept in same repository
parameters:
stage: Batch2
displayName: Deploy Batch2
# dependsOn: Build
baselineVersion: $(BASELINE_VERSION)
flywayLicenseKey: $(FLYWAY_LICENSE_KEY)
workingDirectory: $(WORKING_DIRECTORY)
deploymentTargetsList: deployment-targets-batch-2.csv
pipelineParameters: northwind_pipeline_vars
78 changes: 78 additions & 0 deletions Azure-Templatized-YML-Pipeline-Environments/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# NOTE: This pipeline depends on the following variable groups:

# Name of variable group Keys inside variable group
# ---------------------- --------------------------
# redgate_global_vars FLYWAY_LICENSE_KEY
# redgate_pipeline_vars BASELINE_VERSION, FIRST_UNDO_SCRIPT, AGENT_POOL, SCHEMAS
# redgate_target_database_credentials userName, password, target_database_JDBC, databaseName, check_JDBC, check_userName, check_password

# redgate_build_credentials userName, password, target_database_JDBC, databaseName

# SCHEMAS in pipeline_vars is a comma separated list of schemas used.

# Every target database will need its own variable group, which is referenced in a YML deployment script
# The default is to include the agent pools inside a pipeline definition, to accommodate multiple agent pools.
# If appropriate, the agent pool definition could be moved to the global variable group (or a target specific variable group)

# PARELLELISM
# Pay close attention to the "dependsOn" flag - this determines which block follows each other.
# It's possible to parallelize dpelyments by using multiple agent pools and the "dependsOn" flag.


name: ADO-self-hosted-pipeline-templatized

trigger:
branches:
include:
- prod
paths:
include:
- migrations/*

resources:
repositories:
- repository: templates
type: git
name: templates

variables:
- template: vars.yml@templates

stages:

# - template: rg-clone.yml@templates # templates/deploy.yml if kept in same repository
# parameters:
# stage: Clone
# displayName: Deploy Clone
# cloneImageName: NewWorldDB
# targetCredentials: hr_oracle_test_credentials
# pipelineParameters: hr_oracle_pipeline_vars

- template: deploy.yml@templates # templates/deploy.yml if kept in same repository
parameters:
stage: Test
displayName: Deploy Test
generateDriftAndChangeReport: true # optional flag, defaults to false
staticCodeAnalysis: true # optional flag, defaults to false
targetCredentials: redgate_test_credentials
pipelineParameters: redgate_pipeline_vars

- template: deploy.yml@templates # templates/deploy.yml if kept in same repository
parameters:
stage: Prod1
dependsOn: Test
pauseForCodeReview: true # optional flag, defaults to false
failReleaseIfDriftDetected: true # optional flag, defaults to false
generateDriftAndChangeReport: true # optional flag, defaults to false
staticCodeAnalysis: true # optional flag, defaults to false
displayName: Deploy Prod1
targetCredentials: redgate_prod_credentials
pipelineParameters: redgate_pipeline_vars

- template: deploy.yml@templates # templates/deploy.yml if kept in same repository
parameters:
stage: Prod2
displayName: Deploy Prod2
dependsOn: Test
targetCredentials: redgate_prod2_credentials
pipelineParameters: redgate_pipeline_vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
JDBCString
jdbc:sqlserver://localhost;databaseName=Northwind_Prod1;encrypt=false;integratedSecurity=true;trustServerCertificate=true
jdbc:sqlserver://localhost;databaseName=Northwind_Prod2;encrypt=false;integratedSecurity=true;trustServerCertificate=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
JDBCString
jdbc:sqlserver://localhost;databaseName=Northwind_Prod3;encrypt=false;integratedSecurity=true;trustServerCertificate=true
jdbc:sqlserver://localhost;databaseName=Northwind_Prod4;encrypt=false;integratedSecurity=true;trustServerCertificate=true
Loading