Red Gate forums :: View topic - Work around for lack of dynamic variables - rollback
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation

Deployment Manager PowerShell Scripts forum

Work around for lack of dynamic variables - rollback

Search in Deployment Manager PowerShell Scripts forum
Post new topic   Reply to topic
Jump to:  
Author Message
jtucker@inflexxion.com



Joined: 27 Jun 2013
Posts: 12
Location: Boston

PostPosted: Mon Jan 13, 2014 2:04 pm    Post subject: Work around for lack of dynamic variables - rollback Reply with quote

Red Gate DM is a fine tool, but lacks dynamic variables. That is, a variable that is set at the time of deployment. We need the ability to run a deployment and if it doesn't work properly, revert it. To do so we package up the deployment once and have special code to revert if a variable $IsRollback is true. We simply look at the $RedGateDeploymentComments variable (that IS dynamic - the only one) for a special string.

Code:
# This IsRollingBack routine looks at whether the current project is rolling back the deployment just done.
# It should be called by ALL Deploy, PreDeploy or PostDeploy scripts.
# It utilizes a side-database hosted by ILBUILD02 called DynamicDeployment on SQL2012 instance
# Signature is IsRollingBack($environment, $projectName, $packageDirectoryPath, $forceImportSQLPS)
# where $environment is {Local, Dev, QA, Staging, Live}
#   projectName is the name found in Red Gate DM {painCAS, Assessment Platform, InsideADHD, ...}
#   packageDirectoryPath is the path to which we extract binaries for deployment on the target web server without a trailing backslash (see Variables for your project)
#   forceImportSQLPS should be "true" unless testing this locally

function IsRollingBack($environment, $projectName, $packageDirectoryPath, $forceImportSQLPS)
{
   

   # These values are constant since we only look at dev for these settings
   "Entering Powershell Library: IsRollingBack function..." | Write-Host
   "PackageDirectoryPath is " + $packageDirectoryPath | Write-Host
   "Project is " + $projectName | Write-Host
   "Environment is " + $environment | Write-Host

   
   if ([string]::IsNullOrEmpty($packageDirectoryPath))
   {
      $packageDirectoryPath = "D:\On Deck Circle"   
   }
   $cur = Get-Location
   set-location $packageDirectoryPath

   $IsRollbackResultsFile = $packageDirectoryPath + "\IsRollbackResults.txt"
   "Output of IsRollback in " + $IsRollbackResultsFile | Write-host
   
   $RedGateDeploymentComments | Select-String -Pattern "DoRollbackSaveTheWhales " -AllMatches | out-file $IsRollbackResultsFile -Force

   
   # this stored procedure call will query all the dynamic deployment settings for this environment and project, but we only are concerned with rollback
   # We attempt to select just that row.  If there are no rows in the output file, then rollback is false (but we better flag it).  If True is found in the row, then
   # rollback is true.

   
   $IsRollingBackTrueRowCount = (Get-Content $IsRollbackResultsFile | Select-String "DoRollbackSaveTheWhales" | Measure-Object).Count
   if ($IsRollingBackTrueRowCount -eq 1)
   {
      return 1
   }
   return 0
}
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group