Compare Variables snapshot

I want to be able to see what has changed between two deployments so I’d like to be able to compare the Variables snapshot for the two deployments.
I see from https://github.com/OctopusDeploy/Issues/issues/4700 that the Audit facility can be used to show what changes have been made within a date range but there are issues with this:

  1. I need to work out from the deployments what date/time to use
  2. Each committed change is recorded as a separate audit event
  3. Each audited variable change shows the diff within the context of the entire variable set (rendered as JSON) with no indication of where the differences are which makes finding the changes very tedious
  4. Exporting the audit view results in a CSV file containing embedded HTML which is not a promising start.

I would like to be able to export the Variables snapshots as JSON documents so that I can use local diff tools to be able to compare the two.

Hi David,

Thanks for getting in touch!

It sounds like the best option for you would be to retrieve this information directly from the API. Interacting with the API is made easier using the octopus.client library.

I’ve put together a very basic sample script, that will output the variable snapshot of a single specified release, you could modify this to fit your specific needs such as looping through all releases for a single project or a group of specified releases etc

# You can get this dll from
# https://www.nuget.org/packages/Octopus.Client/
Add-Type -Path 'Octopus.Client.dll' 

$apikey = 'API-XXXXX' # Get this from your profile
$octopusURI = 'http://XXXXXXX' # Your server address
$spaceName = "Default"
$releaseId = 'Releases-186' #Retrieved from the release endpoint /api/releases

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey 
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

# Find Space
$space = $repository.Spaces.FindByName($spaceName)
$repository = New-Object -TypeName Octopus.Client.OctopusRepository $endpoint, ([Octopus.Client.RepositoryScope]::ForSpace($space))


$release = $repository.Releases.Get($releaseId)

$variableSnapshotId = $release.ProjectVariableSetSnapshotId

$variableSnapshot = $repository.VariableSets.Get($variableSnapshotId)

$variableSnapshot| ConvertTo-Json | Out-File "C:\variablesnapshot.json"

I hope this helps get you started, let me know if you have any further questions.

Regards,
Paul

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.