Skip to main content

Release Pipeline

A recommended Octopus release pipeline has six steps:

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

Octopus variables

Set up the project variables first. Several of these are worth putting in a Library Set so the reversal project can share them.

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 deployment package. For a Jira-style convention: DAT-#{Octopus.Release.Number | Replace "\.?\d*$" "" }.
RevertPackageNameFilename for the published reversal package. Include the source package id and the environment so it's clear which deployment a reversal maps to: REVERT-#{Octopus.Environment.Name}-#{Octopus.Action[Download Package].Package.PackageId}.#{Octopus.Action[Download Package].Package.PackageVersion}.nupkg.
HouseKeepDirectoryBase directory on the Tentacle for transient packages: C:\Octopus\Temp\#{Octopus.Environment.Name}.
TempDirectoryPer-release subdirectory under HouseKeepDirectory, shared between steps so packages don't have to be referenced by every step: #{HouseKeepDirectory}\#{Octopus.Action[Download Package].Package.PackageId}-#{Octopus.Action[Download Package].Package.PackageVersion}.

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

Step 1. Download Package

Add a standard Deploy a Package step that downloads the deployment artefact using DynamicPackageName.

Step 2. Download Templates

Another Deploy a Package step, this time for the templates package.

Step 3. DataStar Verify

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

#{WorkItem} and #{Version} are populated from metadata.json in the deployment 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}
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 4. Review Deployment

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

Step 5. DataStar Release

The DataStar Release step template again, this time configured to run the deployment for real, generate a reversal package, and publish that package back to Octopus.

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 EnabledTrue
Working Directory#{TempDirectory}
Template Directory#{TempDirectory}/templates
Package File Name#{RevertPackageName}
Package Directory#{TempDirectory}/package
Package InvariantFalse
Package URIhttps://your-octopus-libary-feed/nuget/packages
Package API Key#{PackageApiKey}
API Key HeaderX-Octopus-ApiKey
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 6. Remove Packages

Add a Run a Script step set to always run, even on failure. Its job is housekeeping: packages were installed into a custom directory so they could be shared between steps, and now need removing. The script below deletes TempDirectory, then 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.