Source Control for Oracle 6

Help for older versions available.

Jenkinsfile pipeline as code (state-based deployments)

Here is a Jenkinsfile that defines a pipeline workflow. Each stage calls a separate batch file that does the real work. This is provided as an example and not designed to be used "as is". For example, this deploys automatically to all environments except production, which may not be desirable.

Jenkinsfile_state Toggle source code

  1. def schemachanges = false
  2. def datachanges = false
  3. node {
  4. /* Begin by cleaning artifacts folder */
  5. try { dir ('Artifacts') { deleteDir() } }
  6. catch (all) { echo "something went wrong with deletedir" }
  7.  
  8.  
  9. stage ('Build') {
  10. checkout scm
  11. def status = bat returnStatus: true, script:'call Tools\\CI-Build.cmd'
  12.  
  13. if (status == 0) {
  14. //archiveArtifacts allowEmptyArchive: true, artifacts:'Artifacts/SchemaCreation.sql, Artifacts/DataCreation.sql, Artifacts/AllObjects.html'
  15. archiveArtifacts allowEmptyArchive: true, artifacts:'Artifacts/ReleaseState.onp'
  16. echo ('Database build was successful')
  17. }
  18. else if (status == 2) error ('No schema objects in the database') // empty schema, fail the build
  19. else error("Something went wrong:$status") // Shouldn't ever get here
  20. }
  21. stage ('Invalid Objects') {
  22. def status = bat returnStatus: true, script:'call Tools\\CI-Invalid-Objects.cmd'
  23. //echo "Invalid Objects exit code: $status"
  24. if (status == 0) echo "No invalid objects found"
  25. else if (status == 1) { // invalid object detected
  26. archiveArtifacts allowEmptyArchive: true, artifacts:'Artifacts/InvalidObjects.txt'
  27. error ('Invalid objects detected - see Artifacts/InvalidObjects.txt') // fail the build
  28. }
  29. else error("Something went wrong:$status") // Shouldn't ever get here
  30.  
  31. }
  32.  
  33. stage ('Code Analysis') {
  34. def status = bat returnStatus: true, script:'call Tools\\CI-Code-Analysis.cmd'
  35. echo "Code analysis exit code: $status"
  36. archiveArtifacts allowEmptyArchive: true, artifacts:'Artifacts/CodeAnalysisResults.xml'
  37. if (status == 0) echo "No code analysis issues found"
  38. else if (status == 1) echo "Some code analysis issues were identified - see Artifacts/CodeAnalysisResults.xml"
  39. }
  40.  
  41. stage ('Unit Test') {
  42. def status = bat returnStatus: true, script:'call Tools\\CI-Unit-Test.cmd'
  43. junit 'Artifacts/UnitTests.junit.xml'
  44. archiveArtifacts allowEmptyArchive: true, artifacts:'Artifacts/UnitTests.junit.xml' //no really need to publish artifact as Jenkins can render the results
  45. if (status == 0) echo "All unit tests passed"
  46. else if (status == 1) error ('One or more unit tests failed - see Tests tab for detail') // fail the build
  47. else error("Something went wrong:$status") // Shouldn't ever get here
  48. }
  49. stage ('QA') {
  50. def status = bat returnStatus: true, script:'call Tools\\Release-QA.cmd'
  51. echo "QA is updated from the desired state"
  52. }
  53. stage ('Release Artifacts') {
  54. def status = bat returnStatus: true, script:'call Tools\\Release-Artifacts.cmd'
  55. // Publish the appropriate artifacts depending on whether there are schema and/or static data differences.
  56. if (status == 63) // Pause the pipeline if there are high warnings detected
  57. {
  58. schemachanges = true // since there must be changes for warnings to be detected
  59. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/Warnings.txt'
  60. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/ReleaseUpdate.sql, Artifacts/ReleaseChanges.html, Artifacts/DataUpdate.sql, Artifacts/DataChanges.html'
  61. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/Rollback.sql'
  62. timeout(time: 10, unit: 'MINUTES') { // timeout after 10 minutes to not block the agent
  63. input 'High warnings detected for schema changes - Abort or Proceed anyway? (only schema changes will be considered for this deployment)' // Proceeding is at your own risk!
  64. }
  65. // In a non-demo scenario it would be recommended to abort the build:
  66. // currentBuild.result = 'ABORTED'
  67. // error("Build aborted owing to detection of high warnings")
  68. }
  69. else if (status == 1) {
  70. // No changes to deploy so in this instance we set currentBuild.result='ABORTED' so that build status isn't marked as failed
  71. currentBuild.result = 'ABORTED'
  72. error ('There are no schema or static data changes to deploy: aborting')
  73. }
  74. else if (status == 2) { // 2 - Schema changes, no static data changes
  75. schemachanges = true
  76. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/ReleaseUpdate.sql, Artifacts/ReleaseChanges.html'
  77. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/Rollback.sql'
  78. }
  79. else if (status == 3) { // 3 - No schema changes, static data changes
  80. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/DataUpdate.sql, Artifacts/DataChanges.html'
  81. datachanges = true
  82. }
  83. else if (status == 4) { // 4 - Schema changes and static data changes
  84. schemachanges = true
  85. datachanges = true
  86. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/ReleaseUpdate.sql, Artifacts/ReleaseChanges.html, Artifacts/DataUpdate.sql, Artifacts/DataChanges.html'
  87. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/Rollback.sql'
  88. }
  89. else error("Something went wrong:$status") // Shouldn't ever get here
  90. echo "There are outstanding changes to deploy: schema changes: $schemachanges, static data changes: $datachanges"
  91. }
  92.  
  93. stage ('Mask') {
  94. def status = bat returnStatus: true, script:"call Tools\\Release-Mask-Acceptance.cmd"
  95. echo "Exit code: $status"
  96. if (status != 0) { // there is a problem
  97. error("Masking failed - see log for details in %LOCALAPPDATA%-Red Gate-Logs-Data Masker for Oracle")
  98. }
  99. }
  100. stage ('Acceptance') {
  101. def status = bat returnStatus: true, script:"call Tools\\Release-Acceptance.cmd $schemachanges $datachanges"
  102. //echo "acceptance status:$status"
  103. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/RollbackState.onp'
  104. if (status == 0) {
  105. echo "No drift detected" // commented out of the demo script
  106. echo "Deployment rehearsal successful"
  107. echo "Roll-back test successful" // commented out of the demo script
  108. }
  109. else if (status == 1) error('Drift detected! See Artifacts/AcceptanceValidation.html') // Drift detected (commented from this demo)
  110. else error("Something went wrong:$status") // Shouldn't ever get here
  111. }
  112.  
  113. stage ('Approval Gate'){
  114. def message = "This allows us to say whether there are schema and/or static data changes to approve"
  115. if (schemachanges && datachanges) message="Schema and static data changes to deploy"
  116. else if (schemachanges && !datachanges) message="Schema changes to deploy"
  117. else if (!schemachanges && datachanges) message="Static data changes to deploy"
  118. // wrapping in a time out so it doesn't block the agent and simply fails the build after 5 minutes if there's no user intervention
  119. timeout(time: 30, unit: 'MINUTES') {
  120. def userInput = input(
  121. id: 'userInput', message: "$message", parameters: [
  122. [$class: 'TextParameterDefinition', defaultValue: 'I Approve The Deployment', description: 'To Proceed, type I Approve The Deployment', name: 'Review deployment artifacts before proceeding']
  123. ])
  124. // echo ("Env: "+userInput)
  125. if (userInput.indexOf('I Approve The Deployment') == -1)
  126. {
  127. currentBuild.result = 'ABORTED'
  128. error('Deployment aborted')
  129. }
  130. }
  131. }
  132.  
  133. stage ('Production') {
  134. def status = bat returnStatus: true, script:"call Tools\\Release-Production.cmd $schemachanges $datachanges"
  135. //echo "Exit code: $status"
  136. if (status == 0) echo "Deployment to production successful" // ideally we'd also run the post-deploy validation check
  137. else if (status == 1) { // Drift detected
  138. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/ProductionDrift.html'
  139. currentBuild.result = 'ABORTED'
  140. error('Drift detected!')
  141. }
  142. else if (status == 61) { // differences after deployment - this isn't implemented in the demo script
  143. archiveArtifacts allowEmptyArchive: true, artifacts: 'Artifacts/ProductionDifferences.html'
  144. error('Post-deploy differences found - something went wrong')
  145. }
  146. else error("Something went wrong:$status") // Shouldn't ever get here
  147. }
  148.  
  149. }

The above Jenkinsfile pipeline references the following batch files, which should be placed inside a Tools folder alongside where the jenkinsfile lives. 

CI-Build.cmd Toggle source code

  1. echo off
  2. echo ========================================================================================================
  3. echo Build a TEST database as a validation step and for testing in the later stages
  4. echo ========================================================================================================
  5.  
  6. echo == Create a schema snapshot that will represent the desired state ==
  7. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /i:sdwgvac /source:Database{HR} "/snp:Artifacts/ReleaseState.onp"
  8. echo snapshot creation exit code:%ERRORLEVEL%
  9.  
  10.  
  11. echo Run Tools/DropAllObjects.sql to drop all objects from the TEST schema
  12. echo on
  13. Call exit | sqlplus HR_TEST/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE))) @Tools/DropAllObjects.sql
  14. echo off
  15.  
  16. echo Build the database with the objects and generate a creation script and a report listing all objects.
  17. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /deploy /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target HR_TEST/Redgate1@localhost/XE{HR_TEST} /sf:Artifacts/SchemaCreation.sql /report:Artifacts/AllObjects.html
  18.  
  19. echo Build database from state:%ERRORLEVEL%
  20.  
  21. rem IF ERRORLEVEL is 0 then there are no changes.
  22. IF %ERRORLEVEL% EQU 0 (
  23. echo == Warning - Is the database empty of schema objects?
  24. SET ERRORLEVEL=2
  25. GOTO END
  26. )
  27.  
  28. rem IF ERRORLEVEL is 61 there are differences, which we expect.
  29. IF %ERRORLEVEL% EQU 61 (
  30. echo == Objects were found and built.
  31. rem Reset the ERRORLEVEL to 0 so the build doesn't fail
  32. SET ERRORLEVEL=0
  33. )
  34.  
  35. echo == Include static data, a feature of Data Compare v5
  36. echo (this step is intentionally left out of this demo script)
  37. rem "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /deploy /source Database{HR} /target HR_TEST/Redgate1@localhost/XE{HR_TEST} /sf:Artifacts/static_data_creation_script.sql
  38. rem IF %ERRORLEVEL% EQU 61 (
  39. rem echo ========================================================================================================
  40. rem echo == Static data was found and added.
  41. rem echo ========================================================================================================
  42. rem rem Reset the ERRORLEVEL to 0 so the build doesn't fail
  43. rem SET ERRORLEVEL=0
  44. rem )
  45.  
  46. echo == Now that we've built a test database, we can validate that the end state schema is consistent with the state
  47. echo (this step is intentionally left out of this demo script)
  48. rem This is optional and is unlikely to fail, so could leave this out to reduce build time.
  49. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /i:sdwgvac /source Database{HR_DEV} /target HR_TEST/Redgate1@localhost/XE{HR_TEST} /report:Artifacts/build_validation_report.html
  50.  
  51. rem There should be no differences
  52. rem IF ERRORLEVEL is 0 then there are no changes.
  53. rem IF %ERRORLEVEL% EQU 0 (
  54. rem echo ========================================================================================================
  55. rem echo == Validation successful! We have successfully built a database from the source state
  56. rem echo ========================================================================================================
  57. rem GOTO END
  58. rem )
  59.  
  60. rem IF %ERRORLEVEL% NEQ 0 (
  61. rem echo ========================================================================================================
  62. rem echo == Validation FAILED! The build isn't consistent with the source
  63. rem echo ========================================================================================================
  64. rem GOTO END
  65. rem )
  66.  
  67.  
  68. :END
  69. EXIT /B %ERRORLEVEL%


DropAllObjects.sql Toggle source code

  1. SET SERVEROUTPUT ON SIZE 1000000
  2. BEGIN
  3. FOR cur_rec IN (SELECT object_name, object_type
  4. FROM user_objects
  5. WHERE object_type IN ('TABLE', 'VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE')) LOOP
  6. BEGIN
  7. IF cur_rec.object_type = 'TABLE' THEN
  8. EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '" CASCADE CONSTRAINTS';
  9. ELSE
  10. EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"';
  11. END IF;
  12. EXCEPTION
  13. WHEN OTHERS THEN
  14. DBMS_OUTPUT.put_line('FAILED: DROP ' || cur_rec.object_type || ' "' || cur_rec.object_name || '"');
  15. END;
  16. END LOOP;
  17. END;
  18. /

CI-Code-Analysis.cmd Toggle source code

  1. echo off
  2. echo ========================================================================================================
  3. echo Run code analysis checks
  4. echo ========================================================================================================
  5.  
  6. echo == This demo uses the preview Code Analysis for Oracle command line
  7. c:\tools\cao\cao.exe /source:Database /outfile:Artifacts\CodeAnalysisResults.xml
  8. echo PMD exit code:%ERRORLEVEL%
  9.  
  10. :END
  11. EXIT /B %ERRORLEVEL%

CI-Unit-Test.cmd Toggle source code

  1. echo off
  2. echo ========================================================================================================
  3. echo Run unit tests
  4. echo ========================================================================================================
  5.  
  6.  
  7. echo This calls the utPLSQL framework
  8. call Tools\utPLSQL-cli\bin\utplsql run HR_TEST/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE))) -f=ut_xunit_reporter -o=Artifacts/UnitTests.junit.xml
  9. echo utplsql:%ERRORLEVEL%
  10.  
  11. :END
  12. EXIT /B %ERRORLEVEL%


Release-Artifacts.cmd Toggle source code

  1. echo off
  2. echo =====================================================================================================
  3. echo == Release Artifacts ==
  4. echo =====================================================================================================
  5.  
  6. echo We generate the deployment preview script artifact here
  7. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /abortonwarnings:High /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /report:Artifacts/ReleaseChanges.html /scriptfile:Artifacts/ReleaseUpdate.sql > Artifacts\Warnings.txt
  8. rem Note that for this demo example /b:e is used to exclude the target schema in the deployment script
  9.  
  10. echo Checking for warnings (no warnings=61, warnings=63), exit code:%ERRORLEVEL%
  11. rem In the unlikely event that the exit code is 63, this mean that a deployment warning has exceeded the allowable threshold (eg, data loss may have been detected)
  12. rem If this occurs it is recommended to review the script, customize it, and perform a manual deployment
  13.  
  14.  
  15. IF %ERRORLEVEL% EQU 63 (
  16. echo ========================================================================================================
  17. echo == High Severity Warnings Detected! Aborting the build.
  18. echo == Review the deployment script and consider deploying manually.
  19. echo ========================================================================================================
  20. rem Here we run the same comparison without /abortonwarnings to generate the deployment script as warnings abort the generation of the deployment script
  21. rem It is useful to keep the deployment script artifact for troubleshooting purposes, or as the starting point for a manual deployment
  22. rem Once we fix the "bug" whereby sco doesn't generate the deployment script when /aow:High finds an issue, then we can remove this step.
  23. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /report:Artifacts/Changes.html /sf:Artifacts/ReleaseUpdate.sql
  24. rem Set the exit code back to 63 as the previous invocaion of sco.exe will reset this.
  25. SET ERRORLEVEL=63
  26. GOTO END
  27. )
  28. rem This is the happy path where we've identified changes and not detected any high warnings
  29. IF %ERRORLEVEL% EQU 61 (
  30. echo ========================================================================================================
  31. echo == Schema changes found to deploy
  32. echo ========================================================================================================
  33.  
  34. echo We generate the roll back script artifact simply by reversing the source and the target for the comparison
  35. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /target:Artifacts/ReleaseState.onp{HR} /source:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /scriptfile:Artifacts/Rollback.sql
  36.  
  37. SET SCHEMACHANGES=1
  38. )
  39. IF %ERRORLEVEL% EQU 0 (
  40. echo ========================================================================================================
  41. echo == No schema changes found to deploy
  42. echo ========================================================================================================
  43. SET SCHEMACHANGES=0
  44. )
  45.  
  46. echo == Now check for static data changes ==
  47. rem if error is "Error: source must specify a connection to a database" then static data needs to be enabled in a feature flag
  48. rem workaround until static data can be deployed from a scripts folder
  49.  
  50. "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /source:"Database{HR}" /target:HR_TEST/Redgate1@localhost/XE{HR_TEST} /deploy
  51. echo Deploy static data to test:%ERRORLEVEL%
  52. "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /include:Countries^|Regions /source:HR_TEST/Redgate1@localhost/XE{HR_TEST} /target:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /reporttype:HTML /report:Artifacts/DataChanges.html /scriptfile:Artifacts/DataUpdate.sql /overwritereports
  53. echo Data Compare exit code:%ERRORLEVEL%
  54. IF %ERRORLEVEL% EQU 64 (
  55. echo ========================================================================================================
  56. echo == DATA COMPARE PROBLEM: returning exit code 64 - ENABLE FEATURE FLAG file OracleToolsFeatures.config and put in:
  57. echo == C:\Windows\System32\config\systemprofile\AppData\Local\Red Gate\
  58. echo ========================================================================================================
  59. )
  60. IF %ERRORLEVEL% EQU 61 (
  61. echo ========================================================================================================
  62. echo == Static data changes found to deploy
  63. echo ========================================================================================================
  64. SET DATACHANGES=1
  65. )
  66. IF %ERRORLEVEL% EQU 0 (
  67. echo ========================================================================================================
  68. echo == No static data changes to deploy
  69. echo ========================================================================================================
  70. SET DATACHANGES=0
  71. )
  72.  
  73. rem deploy static data - v5 feature
  74. rem WARNING - this only works if production has the tables in question. Maybe we need to create the script anyway in the 'null' case?
  75. echo SCHEMACHANGES:%SCHEMACHANGES%
  76. echo DATACHANGES:%DATACHANGES%
  77. rem exit codes:
  78. rem 63 - High Warnings!
  79. rem 1 - No schema changes, no static data changes
  80. if "%SCHEMACHANGES%"=="0" if "%DATACHANGES%"=="0" SET ERRORLEVEL=1
  81. rem 2 - Schema changes, no static data changes
  82. if "%SCHEMACHANGES%"=="1" if "%DATACHANGES%"=="0" SET ERRORLEVEL=2
  83. rem 3 - No schema changes, static data changes
  84. if "%SCHEMACHANGES%"=="0" if "%DATACHANGES%"=="1" SET ERRORLEVEL=3
  85. rem 4 - Schema changes and static data changes
  86. if "%SCHEMACHANGES%"=="1" if "%DATACHANGES%"=="1" SET ERRORLEVEL=4
  87. echo ReleaseReviewErrorlevel:%ERRORLEVEL%
  88.  
  89.  
  90. rem For the purposes of this demo we will provision an empty schema based on production, but ideally a database that closely resembles production should be used
  91.  
  92. echo == Provision an acceptance database ==
  93. echo Run Tools/DropAllObjects.sql to drop all objects from the TEST schema
  94. echo on
  95. Call exit | sqlplus HR_ACCEPTANCE/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE))) @Tools/DropAllObjects.sql
  96. echo off
  97.  
  98. echo == Provision schema
  99. "C:\Program Files\Red Gate\Schema Compare for Oracle \sco.exe" /i:sdwgvac /source HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /target HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /deploy
  100. echo Build Acceptance Schema: %ERRORLEVEL%
  101. echo == Provision data
  102. "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /source HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /target HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /deploy
  103. echo Build Acceptance Data: %ERRORLEVEL%
  104.  
  105.  
  106. :END
  107. EXIT /B %ERRORLEVEL%


Release-QA.cmd Toggle source code

  1. echo off
  2. echo =====================================================================================================
  3. echo == Release QA ==
  4. echo =====================================================================================================
  5.  
  6. rem This syncs an QA database with the latest version so it can be used by a QA team to run regression tests and other manual or automated system tests.
  7. rem There are two approaches to keep a database in sync
  8. rem 1) Use the same process as used for deployment to Acceptance and Production
  9. rem 2) Simply sync the latest changes to the database
  10. rem This example will use (2). If using (1), simply duplicate the process used for Acceptance deployments on your QA database.
  11.  
  12. rem NOTE - This ignores any deployment warnings as these will be picked up by the Review step.
  13.  
  14. echo == Deploying schema changes using state-based deployment
  15. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target HR_QA/Redgate1@localhost/XE{HR_QA} /deploy
  16. rem Exit code will be 61 if there are differences
  17. echo Schema Compare for Oracle /deploy exit code:%ERRORLEVEL%
  18.  
  19. echo == Deploying static data changes using state-based deployment
  20. "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /source:"Database{HR}" /target:HR_QA/Redgate1@localhost/XE{HR_QA} /deploy
  21. echo Data Compare for Oracle /deploy exit code:%ERRORLEVEL%
  22.  
  23. rem Set ERRORLEVEL back to 0 so errors to QA don't cause the pipeline to fail
  24. SET ERRORLEVEL=0
  25.  
  26. echo == Validate against the desired schema state ==
  27. echo (commented out from demo)
  28. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target HR_QA/Redgate1@localhost/XE{HR_QA}
  29. rem echo QA Deployment validation check:%ERRORLEVEL%
  30. rem IF %ERRORLEVEL% EQU 61 (
  31. rem echo ========================================================================================================
  32. rem echo == QA deployment validation failed - review QA_deploy_success_report.html
  33. rem echo ========================================================================================================
  34. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target HR_QA/Redgate1@localhost/XE{HR_QA} /report:Artifacts/QA_deploy_success_report.html
  35. rem GOTO END
  36. rem )
  37.  
  38. :END
  39. EXIT /B %ERRORLEVEL%

Release-Mask-Acceptance Toggle source code

  1. echo off
  2. echo =====================================================================================================
  3. echo == Release-Mask-Acceptance.cmd ==
  4. echo =====================================================================================================
  5.  
  6. rem Acceptance database has been provisioned in the Release-Artifacts stage
  7. echo == Masking Acceptance Contacts table
  8. start /wait "" "C:\Program Files\Red Gate\Data Masker for Oracle\DataMasker.exe" "C:\Program Files\Red Gate\Data Masker for Oracle\MaskingSets\HRContacts.MaskSet" -R -X
  9. echo DataMasker.exe EXIT CODE:%ERRORLEVEL%
  10.  
  11. EXIT /B %ERRORLEVEL%


Release-Acceptance.cmd Toggle source code

  1. echo off
  2. echo =====================================================================================================
  3. echo == Release-Acceptance.cmd ==
  4. echo =====================================================================================================
  5.  
  6. rem This script requires knowledge of whether it needs to deploy schema and/or data
  7. SET RG_SCHEMACHANGES=%1
  8. SET RG_DATACHANGES=%2
  9.  
  10. rem Set some defaults if nothing passed into batch file
  11. IF "%RG_SCHEMACHANGES%"=="" (
  12. SET RG_SCHEMACHANGES=true
  13. SET RG_DATACHANGES=true
  14. )
  15. echo RG_SCHEMACHANGES is:%RG_SCHEMACHANGES%
  16. echo RG_DATACHANGES is:%RG_DATACHANGES%
  17.  
  18. rem Acceptance DRIFT CHECK to validate that the schema state is consistent with production
  19. rem If it isn't, it could be that production has drifted since the acceptance database was provisioned
  20. echo == Check that the acceptance database schema matches production ==
  21. echo (skip the drift check for the demo)
  22. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /target HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /report:Artifacts/acceptance_validation_report.html
  23. rem echo Acceptance vs Production check:%ERRORLEVEL%
  24.  
  25. rem We expect there to be no differences, with exit code 0
  26. rem IF %ERRORLEVEL% EQU 0 (
  27. rem echo == Validation successful: acceptance and production are the same
  28. rem echo Create a schema snapshot artifact of acceptance so we can later use this to perform the production drift check and, if necessary, for selective "roll back".
  29. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /i:sdwgvac /source HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /snapshot:Artifacts/RollbackState.onp
  30. rem )
  31.  
  32. rem IF %ERRORLEVEL% EQU 61 (
  33. rem echo == Validation FAILED! The acceptance database schema isn't consistent with production
  34. rem SET ERRORLEVEL=1
  35. rem GOTO END
  36. rem )
  37.  
  38. echo Create a schema snapshot artifact of acceptance so we can later use this to perform the production drift check and, if necessary, for selective "roll back".
  39. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /i:sdwgvac /source HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /snapshot:Artifacts/RollbackState.onp
  40.  
  41.  
  42. echo == Applying deployment script to the acceptance database ==
  43. IF "%RG_SCHEMACHANGES%" == "true" (
  44. echo on
  45. Call exit | sqlplus "HR_ACCEPTANCE/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE)))" @Artifacts/ReleaseUpdate.sql
  46. echo off
  47. )
  48. IF "%RG_DATACHANGES%" == "true" (
  49. echo == Applying static data to the acceptance database ==
  50. rem Ordinarily should do this using the script - but because the demo unconventionally uses schemas for environments, this isn't possible.
  51. rem echo on
  52. rem Call exit | sqlplus "HR_ACCEPTANCE/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE)))" @Artifacts/DataUpdate.sql
  53. rem echo off
  54. rem Just for the demo we do a state-based deployment to acceptance for static data, rather than running the DataUpdate.sql
  55. rem "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /source:"Database{HR}" /target:HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /deploy
  56.  
  57. rem Workaround for static data deployments - the longer term solution is to deploy from a scripts folder once this is implemented
  58. "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /source:"Database{HR}" /target:HR_TEST/Redgate1@localhost/XE{HR_TEST} /deploy
  59. echo Deploy static data to test:%ERRORLEVEL%
  60. "C:\Program Files\Red Gate\Data Compare for Oracle 5\dco.exe" /include:Countries^|Regions /source:HR_TEST/Redgate1@localhost/XE{HR_TEST} /target:HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /deploy
  61. echo Deploy static data from test to Acceptance:%ERRORLEVEL%
  62.  
  63. SET ERRORLEVEL=0
  64. )
  65. echo Data deploy Acceptance Exit code:%ERRORLEVEL%
  66.  
  67. rem IF %ERRORLEVEL% EQU 61 (
  68. rem echo ========================================================================================================
  69. rem echo == Static data changes found to deploy
  70. rem echo ========================================================================================================
  71. rem SET ERRORLEVEL=0
  72. rem )
  73.  
  74. echo == Check that the deployed acceptance database is now the same as the desired state ==
  75. echo (This is commented out to speed up the demo)
  76.  
  77. rem Can comment this out in demo script for speed purposes
  78. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE}
  79. rem echo Acceptance Deployment Check:%ERRORLEVEL%
  80. rem IF %ERRORLEVEL% EQU 61 (
  81. rem echo ========================================================================================================
  82. rem echo == Acceptance deployment validation failed - review accept_deploy_success_report.html
  83. rem echo ========================================================================================================
  84. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/ReleaseState.onp{HR} /target HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /report:Artifacts/accept_deploy_success_report.html
  85. rem GOTO END
  86. rem )
  87. rem this is optional and will be left out to speed up the demo
  88. echo == Rollback check ==
  89. echo (This is commented out to speed up the demo)
  90. rem Here we find out if there are any warnings associated with a rollback (ie is it possible without data loss?) by generating warnings
  91. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /abortonwarnings:high /b:hdre /i:sdwgvac /source:Artifacts/RollbackState.onp{HR_ACCEPTANCE} /target HR_ACCEPTANCE/Redgate1@localhost/XE{HR_ACCEPTANCE} /report:Artifacts/Rollback_changes_report.html /sf:Artifacts/rollback_script.sql > Artifacts\rollback_warnings.txt
  92. rem echo Acceptance Rollback Warnings ERRORLEVEL:%ERRORLEVEL%
  93.  
  94. rem Exit code 61 is what we expect. It means we can run the rollback with no warnings.
  95. rem Exit code 61 Differences found.
  96. rem IF %ERRORLEVEL% EQU 61 (
  97. rem echo ========================================================================================================
  98. rem echo == Rollback test on acceptance database successful!
  99. rem echo ========================================================================================================
  100. rem SET ERRORLEVEL=0
  101. rem )
  102.  
  103. rem If we get exit code 63, it means that rollback is risky.
  104. rem Exit code 63 Deployment warnings above threshold. Deployment aborted.
  105. rem IF %ERRORLEVEL% EQU 63 (
  106. rem echo ========================================================================================================
  107. rem echo == Rollback has high warnings. A rollback to the snapshot may not be possible.
  108. rem echo ========================================================================================================
  109. rem rem To alert the user we could set the ERRORLEVEL to 1, which the Jenkins job will interpret as "Unstable".
  110. rem rem However, rollback warnings shouldn't stop us from deploying as we should be taking backups anyway.
  111. rem SET ERRORLEVEL=0
  112. rem GOTO END
  113. rem )
  114.  
  115. rem TODO - If we want to fully test the rollback here we could apply the rollback script and check the resulting database against the RollbackState.onp snapshot
  116.  
  117. echo End of Acceptance Exit code:%ERRORLEVEL%
  118.  
  119. :END
  120. EXIT /B %ERRORLEVEL%


Release-Production.cmd Toggle source code

  1. echo off
  2. echo =====================================================================================================
  3. echo == Release-Production ==
  4. echo =====================================================================================================
  5. rem Here we apply the same deployment script that has been reviewed, approved and run successfully on an acceptance or staging database
  6. rem To check that production hasn't drifted since the acceptance database deployment, we run a second drift check.
  7. rem This script requires knowledge of whether it needs to deploy schema and/or data
  8. SET RG_SCHEMACHANGES=%1
  9. SET RG_DATACHANGES=%2
  10.  
  11. rem Set some defaults if nothing passed into batch file
  12. IF "%RG_SCHEMACHANGES%"=="" (
  13. SET RG_SCHEMACHANGES=true
  14. SET RG_DATACHANGES=true
  15. )
  16. echo RG_SCHEMACHANGES is:%RG_SCHEMACHANGES%
  17. echo RG_DATACHANGES is:%RG_DATACHANGES%
  18.  
  19.  
  20. echo == Acceptance Drift Check ==
  21. rem We have previously saved the pre-deployment snapshot state of the acceptance database as an artifact
  22. "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /i:sdwgvac /filter:Database/Filter.scpf /source:Artifacts/RollbackState.onp{HR_ACCEPTANCE} /target:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /report:Artifacts/ProductionDrift.html
  23.  
  24. rem We expect there to be no differences, so ERRORLEVEL should be 0
  25. IF %ERRORLEVEL% EQU 0 (
  26. echo == Confirmed that production has not drifted since the deployment rehearsal
  27. )
  28.  
  29. IF %ERRORLEVEL% NEQ 0 (
  30. echo == DRIFT DETECTED! The production database schema is not at the validated starting point - failing the build
  31. rem We set the exit code to a value that will halt the deployment process.
  32. SET ERRORLEVEL=1
  33. GOTO END
  34. )
  35.  
  36. echo == Deployment time! ==
  37.  
  38. IF "%RG_SCHEMACHANGES%" == "true" (
  39. echo =====================================================================================================
  40. echo Applying the schema changes deployment script
  41. echo =====================================================================================================
  42. echo on
  43. Call exit | sqlplus "HR_PRODUCTION/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE)))" @Artifacts/ReleaseUpdate.sql
  44. echo off
  45. echo SQLPLUS ReleaseUpdate.sql exit code:%ERRORLEVEL%
  46. )
  47. IF "%RG_DATACHANGES%" == "true" (
  48. echo =====================================================================================================
  49. echo Applying the static data changes deployment script - Note this is a Data Compare v5 feature only
  50. echo =====================================================================================================
  51. echo on
  52. Call exit | sqlplus "HR_PRODUCTION/Redgate1@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=localhost)(Port=1521))(CONNECT_DATA=(SID=XE)))" @Artifacts/DataUpdate.sql
  53. echo off
  54. echo SQLPLUS DataUpdate.sql exit code:%ERRORLEVEL%
  55. )
  56.  
  57. echo Check that production is now equal to the desired state
  58. echo (This is commented out to speed up the demo)
  59. rem For there interests of a more efficient demo, can leave out post-deployment validation
  60. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/desired_state_snapshot.onp{HR} /target:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION}
  61.  
  62. rem echo Production Deployment Check:%ERRORLEVEL%
  63. rem IF %ERRORLEVEL% NEQ 0 (
  64. rem echo == Deployment FAILED! The production database schema is not equivalent to the desired state - see prod_deploy_report for differences
  65. rem "C:\Program Files\Red Gate\Schema Compare for Oracle 5\sco.exe" /b:hdre /i:sdwgvac /source:Artifacts/desired_state_snapshot.onp{HR} /target:HR_PRODUCTION/Redgate1@localhost/XE{HR_PRODUCTION} /report:Artifacts/ProductionDifferences.html
  66. rem GOTO END
  67. rem )
  68. rem IF %ERRORLEVEL% EQU 0 (
  69. rem echo == Congratulations - Deployment was successful!
  70. rem GOTO END
  71. rem )
  72.  
  73. :END
  74. EXIT /B %ERRORLEVEL%

Didn't find what you were looking for?