How To: Enforce changes to Lower Environments using Automation
Many organizations have a database policy requiring any change to Production be deployed first in a lower environment. Liquibase Enterprise customers can use the forecast command in their automation script(s) to enforce this type of policy.
Instructions
Sample pipeline
current
hotfix
Linux
In this example, the deploy command looks as such: hammer deploy --labels=$labels --pipeline=$pipeline DEV
Update the script below to remove --labels or --pipeline if not using with the deploy command.
In the Deploy automation workspace include a file called enforce_workflow.sh with example code below. If you deploy with labels or contexts make sure to pass those same parameters to the forecast command.
#!/bin/bash echo "Forecasting to lower environments to check all changes have been deployed" echo "Labels: $1" echo "Pipeline: $2" echo "Current Environment: $3" labels=$1 pipeline=$2 currentEnv=$3 #Check DEV if [ $currentEnv == "DEV" ] then echo "No previous environments" exit 0 fi #Check QA if [ $currentEnv == "QA" ] then echo "Forecasting to DEV" hammer forecast --labels=$labels --pipeline=$pipeline DEV |& tee output.txt if grep -q "There are 0 change sets forecast" "output.txt"; then exit 0 fi fi #Check QA2 if [ $currentEnv == "QA2" ] then echo "No previous environments" exit 0 fi #Check PROD (current) if [ $currentEnv == "PROD" ] && [ $pipeline == "current" ] then echo "Forecasting to QA" hammer forecast --labels=$labels --pipeline=$pipeline QA |& tee output.txt if grep -q "There are 0 change sets forecast" "output.txt"; then exit 0 fi fi #Check PROD (hotfix) if [ $currentEnv == "PROD" ] && [ $pipeline == "hotfix" ] then echo "Forecasting to QA2" hammer forecast --labels=$labels --pipeline=$pipeline QA2 |& tee output.txt if grep -q "There are 0 change sets forecast" "output.txt"; then exit 0 fi fi # Otherwise exit with 1 to indicate Lower Environments have not been satisfied exit 1
Make sure there are executable permissions on enforce_workflow.sh.
In the Deploy script include a call to enforce_workflow.sh.
bash enforce_workflow.sh $(labels) $(PIPELINE) $(deployenv) if [ $? -eq 0 ] then hammer deploy --labels=$(labels) --pipeline=$(PIPELINE) $(deployenv) hammer debug export --include="datical.project,changelog.xml,daticaldb*.log,*.html,deployPackager.properties,packager.log" --report=Reports/debug/ScrubbedDebugFiles.zip else echo "Cannot run deployment until all changes have been deployed to lower environments" hammer debug export --include="datical.project,changelog.xml,daticaldb*.log,*.html,deployPackager.properties,packager.log" --report=Reports/debug/ScrubbedDebugFiles.zip exit 1 fi
Windows
In this example, the deploy command looks as such: hammer deploy --labels=$labels DEV
Update the script below to add --pipeline or any other parameters that are in-use with the deploy command.
In the Deploy automation workspace include a file called enforce_workflow.bat with example code below. If you deploy with labels or contexts make sure to pass those same parameters to the forecast command.
@echo off echo "Forecasting to lower environments to check all changes have been deployed" echo "Labels: %1" echo "Current Environment: %2" SET labels=%1 SET currentEnv=%2 REM Check DEV if "%currentEnv%"=="DEV" ( echo "No previous environments" exit /B 0 ) REM Check QA if "%currentEnv%"=="QA" ( echo "Forecasting to DEV" hammer forecast --labels=%labels% DEV > output.txt echo "Forecast is complete" find "There are 0 change sets forecast" output.txt > NUL && echo All changesets have been deployed to DEV || echo There are changesets that were not deployed to DEV ) REM Check PROD if "%currentEnv%"=="PROD" ( echo "Forecasting to QA" hammer forecast --labels=%labels% QA > output.txt echo "Forecast is complete" find "There are 0 change sets forecast" output.txt > NUL && echo All changesets have been deployed to QA|| echo There are changesets that were not deployed to QA )
Make sure there are executable permissions on enforce_workflow.bat.
In the Deploy script include a call to enforce_workflow.bat.
call enforce_workflow.bat %labels% %deployenv% if ERRORLEVEL 1 ( echo "Cannot run deployment until all changes have been deployed to lower environments" hammer debug export --include="datical.project,changelog.xml,daticaldb*.log,*.html,deployPackager.properties,packager.log" --report=Reports/debug/ScrubbedDebugFiles.zip exit /B 1 ) else ( hammer deploy --labels=%labels% %deployenv% hammer debug export --include="datical.project,changelog.xml,daticaldb*.log,*.html,deployPackager.properties,packager.log" --report=Reports/debug/ScrubbedDebugFiles.zip )
Related content
Copyright © Datical 2012-2020 - Proprietary and Confidential