Created
September 25, 2018 06:00
-
-
Save piers7/d0dd6beaebacf28c2a3810c26d27646b to your computer and use it in GitHub Desktop.
Compare Octopus Deploy Project's current variables with last release's snapshot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Diff's a project's variables with the snapshot associated with its latest release | |
Need to include Octopus.Client nuget package | |
*/ | |
var server = "http://my-octopus-server/"; | |
var projectName = "my-project-name"; | |
// Util.SetPassword("Octopus key for " + server, null); // run this line to unsave the password (if it changes, or you stuff up the entry) | |
var apiKey = Util.GetPassword("Octopus key for " + server, false); | |
var endpoint = new Octopus.Client.OctopusServerEndpoint(server, apiKey); | |
var repository = new Octopus.Client.OctopusRepository(endpoint); | |
var project = repository.Projects.FindByName(projectName); | |
var currentRelease = | |
repository | |
.Releases | |
.FindMany(r => r.ProjectId == project.Id) | |
.OrderByDescending(r => r.Assembled) | |
.FirstOrDefault() | |
; | |
new | |
{ | |
project.Name, | |
project.Description, | |
currentRelease.Version | |
}.Dump(); | |
// Diff the project variables | |
var projectVariables = repository.VariableSets.Get(project.VariableSetId); | |
var releaseSnapshotVariables = repository.VariableSets.Get(currentRelease.ProjectVariableSetSnapshotId); | |
LINQPad.Util.Dif( | |
releaseSnapshotVariables.Variables.OrderBy(v => v.Name).Select(v => new { v.Name, v.Scope, v.Type, v.Value }), | |
projectVariables.Variables.OrderBy(v => v.Name).Select(v => new { v.Name, v.Scope, v.Type, v.Value }) | |
).Dump("Difference (release -> latest)"); | |
projectVariables.Variables.Select(v => v.Name).Except(releaseSnapshotVariables.Variables.Select(v => v.Name)).Dump("New variables, not present in release snapshot"); | |
// Diff associated variable snapshots | |
var projectLibraryVariables = | |
project.IncludedLibraryVariableSetIds | |
.Select(repository.LibraryVariableSets.Get) | |
.Select(vs => vs.VariableSetId) | |
.Select(repository.VariableSets.Get) | |
.SelectMany(vs => vs.Variables) | |
; | |
var releaseLibraryVariables = | |
currentRelease.LibraryVariableSetSnapshotIds | |
.Select(repository.VariableSets.Get) | |
.SelectMany(vs => vs.Variables) | |
; | |
LINQPad.Util.Dif( | |
releaseLibraryVariables.OrderBy(v => v.Name).ThenBy(v => v.Scope.SelectMany(kvp => kvp.Value).FirstOrDefault()).Select(v => new { v.Name, v.Scope, v.Type, v.Value }), | |
projectLibraryVariables.OrderBy(v => v.Name).ThenBy(v => v.Scope.SelectMany(kvp => kvp.Value).FirstOrDefault()).Select(v => new { v.Name, v.Scope, v.Type, v.Value }) | |
).Dump("Library variables diff (release -> latest)"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment