Skip to main content

Reversal Pipeline

The reversal pipeline needs a different lifecycle from the release pipeline: it runs against a single environment, using the reversal package that was generated against that environment. That way each environment is reverted to the state it was in before deployment.

A recommended reversal pipeline has five steps:

  1. Download the reversal package using dynamic package selection.
  2. Run DataStar.Tools in rollback (verify) mode via the step template.
  3. Manual step to review the verify output.
  4. Run DataStar.Tools to apply the reversal.
  5. Housekeeping step to clean up packages.

Octopus variables

Set up the project variables first. Several are worth sharing with the release project via a Library Set.

NameDescription
LicenseKeyA sensitive field containing the DataStar licence key.
PackageApiKeyA sensitive field containing an API key used to publish reversal packages back to the Octopus feed.
ConnectionStringConnection string for the target database. Can reference other variables, for example User ID=#{DbUser};Password=#{DbPassword};Data Source=#{DataSource}.
DynamicPackageNameThe dynamic name used to pick the reversal package. For a Jira-style convention with work item DAT-243432: REVERT-#{Octopus.Environment.Name}-DAT-#{Octopus.Release.Number | Replace "\.?\d*$" "" }.
HouseKeepDirectoryBase directory on the Tentacle for transient packages: C:\Octopus\Temp\#{Octopus.Environment.Name}.
TempDirectoryPer-release subdirectory shared between steps: #{HouseKeepDirectory}\#{Octopus.Action[Download Package].Package.PackageId}-#{Octopus.Action[Download Package].Package.PackageVersion}.

Additional variables may be needed, but the above is the minimum.

Step 1. Download Package

Add a standard Deploy a Package step that downloads the reversal package using DynamicPackageName.

Step 2. DataStar Verify

Add the DataStar Release step template, configured to run in rollback mode. The output log becomes an Octopus artefact so step 3 can review it.

#{WorkItem} and #{Version} are populated from metadata.json in the reversal package via the Variables File parameter.

NameValue
Target databaseMicrosoft
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 tablesFalse
License Key#{LicenseKey}
Work Item / User Story#{WorkItem}
Version#{Version}
Reversal EnabledFalse
Working Directory#{TempDirectory}/content
DataStar Path#{Octopus.Action.Package[DataStarPackage].ExtractedPath}/content
Variables Filemetadata.json
DataStar PackageThe feed and package containing DataStar.Tools.
Rollback TransactionTrue
Output Log Fileverify.txt

Step 3. Review Deployment

Add a standard Manual Intervention Required step. The reviewer reads the verify.txt artefact before approving.

Step 4. DataStar Reversal

The DataStar Release step template again, this time set to run the reversal for real.

NameValue
Target databaseMicrosoft
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 tablesFalse
License Key#{LicenseKey}
Work Item / User Story#{WorkItem}
Version#{Version}
Reversal EnabledFalse
Working Directory#{TempDirectory}/content
DataStar Path#{Octopus.Action.Package[DataStarPackage].ExtractedPath}/content
Variables Filemetadata.json
DataStar PackageThe feed and package containing DataStar.Tools.
Rollback TransactionFalse
Output Log Fileoutput.txt

Step 5. Remove Packages

Add a Run a Script step set to always run, even on failure. It deletes TempDirectory and cleans files older than 15 days out of HouseKeepDirectory to catch anything orphaned by earlier runs.

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

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

Configure the step as always run and cannot skip.