Skip to content

Reversal Pipeline

The reversal pipeline will need a different lifecycle from the release pipeline so that it can be run against a single environment using the reversal package that was created against the same environment. Taking this approach ensures that each environment is reverted to its previous state. A recommended pipeline for the reversal consists of the following steps:

  1. Download the package containing the deployment scripts using the dynamic package selection.
  2. Run the DataStar.Tools deployment in rollback mode using the step template provided.
  3. Manual step to review the output from the verification step.
  4. Run the DataStar.Tools deployment step to apply the reversal package and undo the changes.
  5. Housekeeping step to remove packages.

Octopus Variables

Create a new project in Octopus and start by setting up the variables that are going to be required. We suggest that you create a Library Set for some of these variables so you can share them with the Reversal Project.

Name Description
LicenseKey A sensitive field containing the supplied DataStar license key.
PackageApiKey A sensitive field containing an API Key that you can use to publish reversal packages to the Octopus Feed.
ConnectionString The connection string you use to connect to each target database, this can contain other variable references if you have separate variables for the database username and password.
DynamicPackageName This will vary depending on your naming convention for the reversal packages, for example if we were using a Jira reference DAT-243432 then the value would be REVERT-#{Octopus.Environment.Name}-DAT-#Octopus.Release.Number | Replace "\.?\d*$" "" }
HouseKeepDirectory A base directory location on the tentacle that will be used to hold the various packages: C:\Octopus\Temp\#{Octopus.Environment.Name}
TempDirectory A directory location on the tentacle that will be used to hold the various packages. We recommend using a custom temporary location so that the artifacts can be shared between steps without having to have the packages referenced by each step. For example you might set this to: #{HouseKeepDirectory}\#{Octopus.Action[Download Package].Package.PackageId}-#{Octopus.Action[Download Package].Package.PackageVersion}

You may need to setup additional variables, but the above should be the minimum that would be required.

Step 1 - Download Package

Create a step in your project that will download the deployment artifacts package using the DynamicPackageName variable, this can be done using the standard "Deploy A Package" step.

Step 2 - DataStar Verify

This step will use the step template that you installed for DataStar.Tools. It will be configured to run the deployment in rollback mode and output the log file as a artifact so that it can be reviewed in the next step. There are quite a few options available to you so you should refer to the DataStar.Tools documentation to decide which features you will be using. In the example below we just want to generate the verification output assuming we are using Microsoft SqlServer.

Note: #{WorkItem} and #{Version} will be created provided that you have a metadata.json file with these values populated in the deployment artifacts package. See Variables File below.

Name Value
Target database Microsoft
The name of the database environment #{Octopus.Environment.Name}
The connection string to connect to the target database #{ConnectionString}
Enable writing details to the auditing tables False
License Key #{LicenseKey}
Work Item / User Story #{WorkItem}
Version #{Version}
Reversal Enabled False
Working Directory #{TempDirectory}/content
DataStar Path #{Octopus.Action.Package[DataStarPackage].ExtractedPath}/content
Variables File metadata.json
DataStar Package Set to the feed and package containing the DataStar.Tools
Rollback Transaction True
Output Log File verify.txt

Step 3 - Review Deployment

Add a standard "Manual Intervention Required" step so that the reversal can be reviewed before proceeding.

Step 4 - DataStar Reversal

This step will use DataStar.Tools step template again. This time it will be configured to run the reversal in deployment mode and output the log file as a artifact. Again there are quite a few options available to you so you should refer to the DataStar.Tools documentation to decide which features you will be using.

Note: #{WorkItem} and #{Version} will be created provided that you have a metadata.json file with these values populated in the deployment artifacts package. See Variables File below.

Name Value
Target database Microsoft
The name of the database environment #{Octopus.Environment.Name}
The connection string to connect to the target database #{ConnectionString}
Enable writing details to the auditing tables False
License Key #{LicenseKey}
Work Item / User Story #{WorkItem}
Version #{Version}
Reversal Enabled False
Working Directory #{TempDirectory}/content
DataStar Path #Octopus.Action.Package[DataStarPackage].ExtractedPath}/content
Variables File metadata.json
DataStar Package Set to the feed and package containing the DataStar.Tools
Rollback Transaction False
Output Log File output.txt

Step 5 - Remove Packages

A final step is added to run as script and is set to always run. This is a house keeping step and is required as we have installed our artifacts in a custom location so that they can be shared more easily between steps and now they need to be removed. The script below will delete the #{TempDirectory} and then clean up the parent directory #{HouseKeepDirectory} to remove anything older then 15 days as a safeguard in case any orphaned files where left behind from older executions.

$folderPath = $OctopusParameters["TempDirectory"]
Remove-Item $folderPath -Force  -Recurse -ErrorAction SilentlyContinue

$houseKeepPath = $OctopusParameters["HouseKeepDirectory"]
if (![string]::IsNullOrEmpty($houseKeepPath)) 
{
    $limit = (Get-Date).AddDays(-15)
    # Delete files older than the $limit.
    Get-ChildItem -Path $houseKeepPath -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force -Recurse
}

Note: this step is set to cannot skip and always run

Back to top