...
Liquibase Enterprise requires two repositories which are referred to as Repos in Azure DevOps. Azure Pipelines can be built from code stored in Azure Repos, Bitbucket, GitHub, and other Git or Subversion sources. For this example we will be using Azure Repos.
In Azure Repos create the following two projects:
The Liquibase Project repository.
The SQL code repository.
This example also uses 2 optional repos:
A centralized Rules repository.
A centralized CI/CD repository.
Push the Liquibase project configuration files to the project repository in Azure Repos.
...
This example uses SSH keys for git authentication. You can find information on using SSH keys with Azure at https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops. Copy the SSH private key your ~/.ssh
folder.
If you wish to use HTTPS for git authentication you will need to setup Git Credential Manager. Instructions can be found at https://learn.microsoft.com/en-us/azure/devops/repos/git/set-up-credential-managers?view=azure-devops.
...
The example .gitlab-ci.yml file should be placed in the top level of the SQL repo. Update the GitLab URLs for your Repos.
Code Block |
---|
#trigger: Liquibasenone Sample gitlab-ci.yml stages: - package - forecast - deploy - logging packager-job: stage: package tags: - liquibase only name: $(Application.Name)-$(Build.BuildId) variables: - template: ./variables.yml - group: Liquibase_Variables pool: name: $(Agent.PoolName) workspace: clean: all resources: refs: - developrepositories: - variablesrepository: DDB_REPOSITORY name: -ABC_DDB $jobtype == "PACKAGER" excepttype: git variables connection: AzureRepos source: ABC_DDB # Don't execute when Liquibase commits back to the Repo. ref: 'refs/heads/main' - repository: SQL_REPOSITORY -name: $CIABC_COMMIT_AUTHOR == "Liquibase <support@liquibase.com>"SQL scripttype: git -connection: |AzureRepos source: ABC_SQL echo "Packaging Stage" ref: 'refs/heads/current' echo- "Checking Environment"repository: CICD_REPOSITORY echo Project directoryname: $CI_PROJECT_DIRLiquibase/DB_CICD_PIPELINES type: git echo Project ID: $CI_PROJECT_ID connection: AzureRepos echo Commit Authorsource: $CI_COMMIT_AUTHORLiquibase/DB_CICD_PIPELINES ref: 'refs/heads/main' whoami - repository: CENTRALIZED_RULES_REPOSITORY # Variables needed for Oracle projects.name: Liquibase/CENTRALIZED_RULES type: git export PATH="$PATH:/opt/datical/DaticalDB/repl:/opt/datical/DaticalDB/instantclient" connection: AzureRepos export LD_LIBRARY_PATH=/opt/datical/DaticalDB/instantclient source: Liquibase/CENTRALIZED_RULES hammer show version - | echo "Getting SQL repo" cd .. rm src -r -f mkdir -p src 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 cd src hammer show version git config --global user.name "Liquibase echo $(System.DefaultWorkingDirectory) export PATH="$PATH:/opt/mssql-tools/bin" displayName: 'Run Prechecks' git config --global user.email "support@liquibase.com"script: | cd $(Git.Repository) git config --global init.defaultBranch main cp -R ../CENTRALIZED_RULES/Rules . printenv git init hammer groovy deployPackager.groovy pipeline=current git remote add origin git@gitlab.com:mbohls/$sql_repo.git git fetch origin git checkout -b $branch --track origin/$branch git branch --set-upstream-to=origin/$branch $branch - | echo "Getting DDB repo" cd .. rm ddb -r -f mkdir -p ddb cd ddb git config --global user.name "Liquibase" git config --global user.email "support@liquibase.com" git config --global init.defaultBranch main git init git remote add origin git@gitlab.com:mbohls/$ddb_repo.git git fetch origin git checkout -b main --track origin/main git branch --set-upstream-to=origin/main main - | echo "Packaging" hammer groovy deployPackager.groovy pipeline=$pipeline scm=true labels=$CI_JOB_ID zip -r $appname-$CI_JOB_ID.zip * -x "Reports/*" -x "Logs/*" -x "Snapshots/*" -x "Profiles/*" -x "daticaldb.log" -x "deployPackager.properties"; mv $appname-$CI_JOB_ID.zip $CI_PROJECT_DIR artifacts: paths: - $appname-$CI_JOB_ID.zip forecast-job: stage: forecast tags: - liquibase only: refs: - web variables: - $jobtype == "FORECAST" script: - | echo "Forecast Stage" echo Project directory: $CI_PROJECT_DIR echo Artifact ID: $packagenumber export PATH="$PATH:/opt/datical/DaticalDB/repl" export LD_LIBRARY_PATH=/opt/datical/DaticalDB/instantclient cd ../ddb mkdir -p forecast cd forecast # Get GitLab Artifact curl --output $appname-$packagenumber.zip --header "PRIVATE-TOKEN: <your PAT>" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$packagenumber/artifacts/$appname-$packagenumber.zip" # Unzip and forecast unzip $appname-$packagenumber.zip if [ -n "${labels}" ] then hammer forecast $environment --labels="${labels}" else hammer forecast $environment fi deploy-job: stage: deploy tags: - liquibase only: refs: - web variables: - $jobtype == "DEPLOY" script: - | echo "Deploy Stage" echo Project directory: $CI_PROJECT_DIR echo Artifact ID: $packagenumber export PATH="$PATH:/opt/datical/DaticalDB/repl" export LD_LIBRARY_PATH=/opt/datical/DaticalDB/instantclient cd ../ddb mkdir -p deploy cd deploy # Get GitLab Artifact curl --output $appname-$packagenumber.zip --header "PRIVATE-TOKEN: yourtoken" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/jobs/$packagenumber/artifacts/$appname-$packagenumber.zip" # Unzip and deploy unzip $appname-$packagenumber.zip if [ -n "${labels}" ] then hammer deploy $environment --labels="${labels}" else hammer deploy $environment fi logging-job: stage: logging tags: - daticaldb except: variables: # Don't execute when Liquibase commits to the repo. - $CI_COMMIT_AUTHOR == "Liquibase <support@liquibase.com>" && $jobtype == "PACKAGER" script: - | # Generate log files for debugging echo "Post Stage" echo Project directory: $CI_PROJECT_DIR export PATH="$PATH:/opt/datical/DaticalDB/repl:/opt/datical/DaticalDB/instantclient" export LD_LIBRARY_PATH=/opt/datical/DaticalDB/instantclient # Switch to the DDB directory cd ../ddb hammer debug export --include="datical.project,changelog.xml,daticaldb*.log,*.html,deployPackager.properties,packager.log" --report=scrubbed_debug_files-$CI_JOB_ID.zip mv scrubbed_debug_files-$CI_JOB_ID.zip $CI_PROJECT_DIR # Run even if there was a job failure earlier so that we capture the log files. when: always artifacts: paths: - scrubbed_debug_files-$CI_JOB_ID.zip variables: #These are runtime variables. Global variables are set at the project level. environment: value: "ref" description: "DBDEF name. Valid values are: ref, test, prod" jobtype: value: "PACKAGER" description: "valid values are: PACKAGER, FORECAST, DEPLOY" packagenumber: value: "changeme" description: "FORECAST and DEPLOY JOBS ONLY. Unique number of artifact" labels: description: "FORECAST and DEPLOY JOBS ONLY. Label expression"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) - script: | pwd cd $(Git.Repository) echo $name zip -q -r $(Application.Name)-$(Build.BuildId).zip * mkdir -p $(System.DefaultWorkingDirectory)/artifacts ls -l $(Application.Name)-$(Build.BuildId).zip cp $(Application.Name)-$(Build.BuildId).zip $(System.DefaultWorkingDirectory)/artifacts displayName: 'Copy zip to Azure Artifacts' - upload: $(System.DefaultWorkingDirectory)/artifacts/$(Application.Name)-$(Build.BuildId).zip artifact: drop - task: ArtifactoryGenericUpload@2 inputs: artifactoryService: 'ArtifactoryCS' specSource: 'taskConfiguration' fileSpec: | { "files": [ { "pattern": "$(Git.Repository)/$(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 |
Note: You may need to manually initialize the git SSH key for both of the Repos.
...