...
This document explains how to setup an Azure pipeline with an agent to execute Liquibase Enterprise operations. An Azure DevOps agent can be shared among multiple projects, so one agent can serve several teams. You can learn more about Azure agents here: https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser.
Additionally we’ll show how Liquibase Enterprise forecast and deploy commands can run via an Azure Release using a Classic release pipeline: https://learn.microsoft.com/en-us/azure/devops/pipelines/release/?view=azure-devops
Instructions
Table of Contents |
---|
...
Code Block |
---|
trigger: none name: $(Application.Name)-$(Build.BuildId) variables: - template: ./variables.yml - group: Liquibase_Variables pool: name: $(Agent.PoolName) workspace: clean: all resources: repositories: - repository: DDB_REPOSITORY name: ABC_DDB type: git connection: AzureRepos source: ABC_DDB ref: 'refs/heads/main' - repository: SQL_REPOSITORY name: ABC_SQL type: git connection: AzureRepos source: ABC_SQL ref: 'refs/heads/current' - repository: CICD_REPOSITORY name: Liquibase/DB_CICD_PIPELINES type: git connection: AzureRepos source: Liquibase/DB_CICD_PIPELINES ref: 'refs/heads/main' - repository: CENTRALIZED_RULES_REPOSITORY name: Liquibase/CENTRALIZED_RULES type: git connection: AzureRepos source: Liquibase/CENTRALIZED_RULES ref: 'refs/heads/main' steps: - checkout: DDB_REPOSITORY persistCredentials: true clean: true - checkout: SQL_REPOSITORY clean: true fetchDepth: 100 persistCredentials: true - checkout: CENTRALIZED_RULES_REPOSITORY clean: true persistCredentials: true - script: | whoami hammer show version echo $(System.DefaultWorkingDirectory) displayName: printenv displayName: 'Run Prechecks'Run Prechecks' # Ensure the PATH includes the necessary executables, eg. hammer and sqlplus/sqlcmd/clpplus/psql # Also copy the Rules from the Centralized rules folder to the DDB folder - powershell: | $Env:Path += ";C:\Users\Administrator\DaticalDB\repl" $Env:Path += ";C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\" cd $(Git.Repository) xcopy /s/e/y ..\CENTRALIZED_RULES\Rules\. .\Rules\* condition: eq( variables['Agent.OS'], 'Windows_NT' ) displayName: 'Update PATH (Windows) and set Rules' - script: | export PATH="$PATH:/opt/datical/DaticalDB/repl" export PATH="$PATH:/opt/mssql-tools/bin" cd $(Git.Repository) cp -R ../CENTRALIZED_RULES/Rules . condition: eq( variables['Agent.OS'], 'Linux' ) displayName: 'Update PATH (Linux) and set Rules' - script: | cd $(Git.Repository) hammer groovy deployPackager.groovy pipeline=current commitPrefix="[skip ci]" scm=true labels=$(Build.BuildId),current if [ $? -ne 0 ]; then exit 1; fi displayName: 'Run Liquibase packager' env: DDB_USER: $(Liquibase-abc-ref1-User) DDB_PASS: $(Liquibase-abc-ref1-Pass) DDB_DMCDB_USER: $(Liquibase-abc-dmc-User) DDB_DMCDB_PASS: $(Liquibase-abc-dmc-Pass) # Compress files into .zip - task: ArchiveFiles@2 inputs: rootFolderOrFile: '$(System.DefaultWorkingDirectory)/$(Git.Repository)' includeRootFolder: true archiveType: 'zip' archiveFile: '$(System.DefaultWorkingDirectory)/artifacts/$(Application.Name)-$(Build.BuildId).zip' - upload: $(System.DefaultWorkingDirectory)/artifacts/$(Application.Name)-$(Build.BuildId).zip artifact: drop - task: ArtifactoryGenericUpload@2 inputs: artifactoryService: 'ArtifactoryCS' specSource: 'taskConfiguration' fileSpec: | { "files": [ { "pattern": "artifacts/$(Application.Name)-$(Build.BuildId).zip", "target": "$(Project.Name)/$(Application.Name)/" } ] } replaceSpecVars: true specVars: '$(Application.Name),$(Build.BuildId)' collectBuildInfo: true buildName: '$(Build.DefinitionName)' buildNumber: '$(Build.BuildNumber)' module: '$(Project.Name)' failNoOp: true displayName: 'Upload zip to artifactory' - task: ArtifactoryPublishBuildInfo@1 inputs: artifactoryService: 'ArtifactoryCS' buildName: '$(Build.DefinitionName)' buildNumber: '$(Build.BuildNumber)' displayName: 'Publish Build Info to artifactory' - task: ArtifactoryBuildPromotion@1 inputs: artifactoryService: 'ArtifactoryCS' buildName: '$(Build.DefinitionName)' buildNumber: '$(Build.BuildNumber)' targetRepo: '$(Project.Name)' status: 'Released' sourceRepo: '$(Project.Name)' includeDependencies: false copy: false dryRun: false displayName: 'Promote Build to artifactory' - task: AzureKeyVault@2 inputs: azureSubscription: 'CustomerSuccessPayAsGo' KeyVaultName: 'cs-key-vault1' SecretsFilter: '*' RunAsPreJob: true |
...
Step 8: Create a Release to run Forecast and Deploy Jobs
Use an Azure Release to run the Deploy Packager (Build) job. Azure Pipelines are created from an azure_pipelines.yml file.
...
Instructions: https://learn.microsoft.com/en-us/azure/devops/pipelines/release/?view=azure-devops
Azure Releases can be used to run the Liquibase Enterprise Forecast and Deploy jobs. These jobs will pull the repository from an Artifact.
Under Releases select + NEW to create a New Release Pipeline. Add an artifact. This example uses a JFrog Artifactory artifact. For JFrog Artifactory you will need to have setup an Artifactory Service, see https://www.jfrog.com/confluence/display/JFROG/Artifactory+Azure+DevOps+Extension.
...
For the Build Name, select the build pipeline you created in Step 7.
...
Step 9: Configure your Release Pipeline
In this example we have setup the following workflow:
Deploy to DEV → Forecast to Test → Deploy to Test → Forecast to Prod → Deploy to Prod
...
Under the Variables section, make sure to Link the Variable Group created in Step 6.
...
Each step represents a Stage in the Pipeline.
Configure a Forecast Stage
For each Forecast Stage, select the Agent that will be used to run the job. Be sure to select the Agent configured in Step 2.
...
Each Azure Stage is comprised of Tasks. Use a Command line task to run the Liquibase Enterprise hammer commands.
Be sure to unzip the artifact prior to running the hammer commands.
You’ll need to specify the Working Directory under the Advanced section.
You’ll also want to set
DDB_USER
,DDB_PASS
,DDB_DMCDB_USER
, andDDB_DMCDB_PASS
under the Environment Variables section.
Script Code:
Code Block |
---|
whoami
hammer show version
unzip -o *.zip
hammer deploy --labels=current --pipeline=current DEV |
...
Configure a Deploy Stage
A Deploy Stage will be identical to a Forecast stage with the exception of the Script Code.
For Deploys use the following:
Code Block |
---|
whoami
hammer show version
unzip -o *.zip
hammer deploy --labels=current --pipeline=current TEST |
Step 10: Test your Pipeline
Commit a change to the packaging branch in your SQL repo. GitLab should run the pipeline Packaging job using your runner.. Go to your Pipeline in Azure and select “Run pipeline”.
...
After all your pipeline steps have completed successfully, your artifact will be ready to run a Release.
...
Go to Releases and select “Create release”.
...