Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ByronScottJones/53e68df78cd16377afe51ae3f1ff501a to your computer and use it in GitHub Desktop.
Save ByronScottJones/53e68df78cd16377afe51ae3f1ff501a to your computer and use it in GitHub Desktop.
Octopus Deploy - Step Template - Log Octopus Parameters
{
"Id": "5fc03a6a-8713-4b95-8e5a-38eeb00d4248",
"Name": "Octopus - Log OctopusParameters",
"Description": "Writes the $OctopusParameters Dictionary to the Log.\nFor debugging purposes.",
"ActionType": "Octopus.Script",
"Version": 1,
"Author": "https://github.com/ByronScottJones",
"Properties": {
"Octopus.Action.RunOnServer": "true",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "write-host \"# Copy this log section to a Powershell Editor or terminal. and run it.\"\r\nwrite-host \"# It will create an `$OctopusDeploy Dictionary Variable.\"\r\nwrite-host \" \"\r\n\r\nwrite-host \"function info { param([string] `$time) process {}}\"\r\nwrite-host \"`$OctopusParameters = @{}\"\r\nforeach($Key in ($OctopusParameters.Keys | sort-object)) {\r\n $Value = $OctopusParameters[$Key]\r\n \r\n $Encode = $false\r\n if( $Value -match \"\\(\" ) {$Encode = $true }\r\n if( $Value -match '\\)' ) {$Encode = $true }\r\n if( $Value -match '\\{' ) {$Encode = $true }\r\n if( $Value -match '\\}' ) {$Encode = $true }\r\n if( $Value -match '\\[' ) {$Encode = $true }\r\n if( $Value -match '\\]' ) {$Encode = $true }\r\n if( $Value -match '\\\"' ) {$Encode = $true }\r\n if( $Value -match '\\`' ) {$Encode = $true }\r\n if( $Value -match \"\\`'\" ) {$Encode = $true }\r\n if( $Value -match '\\#' ) {$Encode = $true }\r\n if( $Value -match '\\\\' ) {$Encode = $true }\r\n if( $Value -match '\\/' ) {$Encode = $true }\r\n\r\n if($Encode) {\r\n $Base64Out = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($OctopusParameters[$Key]))\r\n $Value = \"`$([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String(`\"$Base64Out`\")))\"\r\n }\r\n\r\n write-host \"`$OctopusParameters.Add(`\"$Key`\", `\"$Value`\")\"\r\n\r\n \r\n} #foreach Key\r\n\r\nwrite-host \"`$OctopusParameters | add-member -memberType ScriptMethod -Name ToClipboard -value {`$this.GetEnumerator() |sort -Property Name | format-table -AutoSize | out-string -width 512 | set-clipboard; };\"\r\nwrite-host \"`$OctopusParameters | add-member -memberType ScriptMethod -Name ToGridView -value {`$this.GetEnumerator() |sort -Property Name | out-gridview; };\"\r\nwrite-host \"`$OctopusParameters | add-member -memberType ScriptMethod -Name ToScreen -value {`$this.GetEnumerator() |sort -Property Name | format-table -AutoSize | out-string -width 512; };\"\r\n\r\nwrite-host \"CLS\"\r\nwrite-host \" \"\r\nwrite-host \"write-host `\"To display a gridview of the Octopus Parameters, run this command: ```$OctopusParameters.ToGridView()`\"\"\r\nwrite-host \"write-host `\"To list the Octopus Parameters, run this command: ```$OctopusParameters.ToScreen()`\"\"\r\nwrite-host \"write-host `\"To copy the Octopus Parameters to the clipboard, run this command: ```$OctopusParameters.ToClipboard()`\"\" \r\n"
},
"SensitiveProperties": {},
"Parameters": [],
"LastModifiedOn": "2020-06-05T20:16:48.674+00:00",
"LastModifiedBy": "https://github.com/ByronScottJones",
"$Meta": {
"ExportedAt": "2020-06-05T20:53:50.888Z",
"OctopusVersion": "2.6.5.1010",
"Type": "ActionTemplate"
},
"Category": "octopus"
}
@ByronScottJones
Copy link
Author

ByronScottJones commented Jun 9, 2020

octopus-LogOctopusParameters

Creates and writes a powershell script to the Release Task Log during deployment. This powershell script can be copy/pasted to a powershell console, and it will generate an $OctopusParameters variable with all of the values used during the deployment, along with helper methods .ToGridView(), .ToScreen(), and .ToClipBoard() which should be self explanatory. This should help with debugging deployments.

This is what the log output looks like for this step:

Tentacle Script Execution


 #Copy this log section to a Powershell Editor or terminal. and run it.
 #It will create an $OctopusDeploy Dictionary Variable.
 
function info { param([string] $time) process {}}
$OctopusParameters = @{}
$OctopusParameters.Add("Parameter_1", "Foo")
$OctopusParameters.Add("Parameter_2", "Bar")
#... one line for every OctopusParameter entry
$OctopusParameters | add-member -memberType ScriptMethod -Name ToClipboard -value {$this.GetEnumerator() |sort -Property Name | format-table -AutoSize | out-string -width 512 | set-clipboard; };
$OctopusParameters | add-member -memberType ScriptMethod -Name ToGridView  -value {$this.GetEnumerator() |sort -Property Name | out-gridview; };
$OctopusParameters | add-member -memberType ScriptMethod -Name ToScreen    -value {$this.GetEnumerator() |sort -Property Name | format-table -AutoSize | out-string -width 512; };
CLS
 
write-host "To display a gridview of the Octopus Parameters, run this command: `$OctopusParameters.ToGridView()"
write-host "To list the Octopus Parameters, run this command: `$OctopusParameters.ToScreen()"
write-host "To copy the Octopus Parameters to the clipboard, run this command: `$OctopusParameters.ToClipboard()"
Info    14:30:17
==============================================
PowerShell exit code: 0
==============================================

As you can see, it literally outputs a new powershell script, which can then be used for further development and debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment