Skip to content

Commit 1fdf03e

Browse files
authored
Merge pull request #1615 from benjimac93/master
Fix shortened Release Notes Substring
2 parents 434c234 + d3ec048 commit 1fdf03e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

step-templates/slack-detailed-notification.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"Name": "Slack - Detailed Notification",
44
"Description": "Posts deployment status to Slack optionally including additional details (release number, environment name, release notes etc.) as well as error description and link to failure log page.",
55
"ActionType": "Octopus.Script",
6-
"Version": 10,
6+
"Version": 11,
77
"Properties": {
8-
"Octopus.Action.Script.ScriptBody": "function Slack-Populate-StatusInfo ([boolean] $Success = $true) {\n\n\t$deployment_info = $OctopusParameters['DeploymentInfoText'];\n\t\n\tif ($Success){\n\t\t$status_info = @{\n\t\t\tcolor = \"good\";\n\t\t\t\n\t\t\ttitle = \"Success\";\n\t\t\tmessage = \"$deployment_info\";\n\n\t\t\tfallback = \"Deployed successfully $deployment_info\";\n\t\t\t\n\t\t\tsuccess = $Success;\n\t\t}\n\t} else {\n\t\t$status_info = @{\n\t\t\tcolor = \"danger\";\n\t\t\t\n\t\t\ttitle = \"Failed\";\t\t\t\n\t\t\tmessage = \"$deployment_info\";\n\n\t\t\tfallback = \"Failed to deploy $deployment_info\";\t\n\t\t\t\n\t\t\tsuccess = $Success;\n\t\t}\n\t}\n\t\n\treturn $status_info;\n}\n\nfunction Slack-Populate-Fields ($StatusInfo) {\n\n\t# We use += instead of .Add() to prevent returning values returned by .Add() function\n\t# it clutters the code, but seems the easiest solution here\n\t\n\t$fields = @()\n\t\n\t$fields += \n\t\t@{\n\t\t\ttitle = $StatusInfo.title;\n\t\t\tvalue = $StatusInfo.message;\n\t\t}\n\t;\n\n\t$IncludeFieldEnvironment = [boolean]::Parse($OctopusParameters['IncludeFieldEnvironment'])\n\tif ($IncludeFieldEnvironment) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Environment\";\n\t\t\t\tvalue = $OctopusEnvironmentName;\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\n\n\n\t$IncludeFieldMachine = [boolean]::Parse($OctopusParameters['IncludeFieldMachine'])\n\tif ($IncludeFieldMachine) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Machine\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Machine.Name'];\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t$IncludeFieldTenant = [boolean]::Parse($OctopusParameters['IncludeFieldTenant'])\n\tif ($IncludeFieldTenant) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Tenant\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Deployment.Tenant.Name'];\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t\t$IncludeFieldUsername = [boolean]::Parse($OctopusParameters['IncludeFieldUsername'])\n\tif ($IncludeFieldUsername) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Username\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Deployment.CreatedBy.Username'];\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t$IncludeFieldRelease = [boolean]::Parse($OctopusParameters['IncludeFieldRelease'])\n\tif ($IncludeFieldRelease) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Release\";\n\t\t\t\tvalue = $OctopusReleaseNumber;\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\n\t\n\t\n\t$IncludeFieldReleaseNotes = [boolean]::Parse($OctopusParameters['IncludeFieldReleaseNotes'])\n\tif ($StatusInfo[\"success\"] -and $IncludeFieldReleaseNotes) {\n\t\n\t\t\n\t\t$link = $OctopusParameters['Octopus.Web.ReleaseLink'];\n\t\t$baseurl = $OctopusParameters['OctopusBaseUrl'];\n\t\t\n\t\t$notes = $OctopusReleaseNotes\n\t\t\n\t\tif ($notes.Length -gt 300) {\n\t\t\t$shortened = $OctopusReleaseNotes.Substring(0,0);\n\t\t\t$notes = \"$shortened `n `<${baseurl}${link}|view all changes`>\"\n\t\t}\n\t\t\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Changes in this release\";\n\t\t\t\tvalue = $notes;\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t#failure fields\n\t\n\t$IncludeErrorMessageOnFailure = [boolean]::Parse($OctopusParameters['IncludeErrorMessageOnFailure'])\n\tif (-not $StatusInfo[\"success\"] -and $IncludeErrorMessageOnFailure) {\n\t\t\t\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Error text\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Deployment.Error'];\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\t\n\n\t$IncludeLinkOnFailure = [boolean]::Parse($OctopusParameters['IncludeLinkOnFailure'])\n\tif (-not $StatusInfo[\"success\"] -and $IncludeLinkOnFailure) {\n\t\t\n\t\t$link = $OctopusParameters['Octopus.Web.DeploymentLink'];\n\t\t$baseurl = $OctopusParameters['OctopusBaseUrl'];\n\t\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"See the process\";\n\t\t\t\tvalue = \"`<${baseurl}${link}|Open process page`>\";\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\n\t\n\t\n\treturn $fields;\n\t\n}\n\nfunction Slack-Rich-Notification ($Success)\n{\n $status_info = Slack-Populate-StatusInfo -Success $Success\n\t$fields = Slack-Populate-Fields -StatusInfo $status_info\n\n\t\n\t$payload = @{\n channel = $OctopusParameters['Channel']\n username = $OctopusParameters['Username'];\n icon_url = $OctopusParameters['IconUrl'];\n\t\t\n attachments = @(\n @{\n\t\t\t\tfallback = $status_info[\"fallback\"];\n\t\t\t\tcolor = $status_info[\"color\"];\n\t\t\t\n\t\t\t\tfields = $fields\n };\n );\n }\n\t\n\t#We unescape here to allow links in the Json, as ConvertTo-Json escapes <,> and other special symbols\n\t$json_body = ($payload | ConvertTo-Json -Depth 4 | % { [System.Text.RegularExpressions.Regex]::Unescape($_) });\n\t\n\t\n try {\n \t$invokeParameters = @{}\n $invokeParameters.Add(\"Method\", \"POST\")\n $invokeParameters.Add(\"Body\", $json_body)\n $invokeParameters.Add(\"Uri\", $OctopusParameters['HookUrl'])\n $invokeParameters.Add(\"ContentType\", \"application/json\")\n \n # Check for UseBasicParsing\n if ((Get-Command Invoke-RestMethod).Parameters.ContainsKey(\"UseBasicParsing\"))\n {\n # Add the basic parsing argument\n $invokeParameters.Add(\"UseBasicParsing\", $true)\n }\n\n \n [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n Invoke-RestMethod @invokeParameters\n \n } catch {\n echo \"Something occured\"\n echo $_.Exception\n echo $_\n #echo $json_body\n throw\n }\n \n}\n\n\n\n$success = ($OctopusParameters['Octopus.Deployment.Error'] -eq $null);\n\nSlack-Rich-Notification -Success $success\n",
8+
"Octopus.Action.Script.ScriptBody": "function Slack-Populate-StatusInfo ([boolean] $Success = $true) {\n\n\t$deployment_info = $OctopusParameters['DeploymentInfoText'];\n\t\n\tif ($Success){\n\t\t$status_info = @{\n\t\t\tcolor = \"good\";\n\t\t\t\n\t\t\ttitle = \"Success\";\n\t\t\tmessage = \"$deployment_info\";\n\n\t\t\tfallback = \"Deployed successfully $deployment_info\";\n\t\t\t\n\t\t\tsuccess = $Success;\n\t\t}\n\t} else {\n\t\t$status_info = @{\n\t\t\tcolor = \"danger\";\n\t\t\t\n\t\t\ttitle = \"Failed\";\t\t\t\n\t\t\tmessage = \"$deployment_info\";\n\n\t\t\tfallback = \"Failed to deploy $deployment_info\";\t\n\t\t\t\n\t\t\tsuccess = $Success;\n\t\t}\n\t}\n\t\n\treturn $status_info;\n}\n\nfunction Slack-Populate-Fields ($StatusInfo) {\n\n\t# We use += instead of .Add() to prevent returning values returned by .Add() function\n\t# it clutters the code, but seems the easiest solution here\n\t\n\t$fields = @()\n\t\n\t$fields += \n\t\t@{\n\t\t\ttitle = $StatusInfo.title;\n\t\t\tvalue = $StatusInfo.message;\n\t\t}\n\t;\n\n\t$IncludeFieldEnvironment = [boolean]::Parse($OctopusParameters['IncludeFieldEnvironment'])\n\tif ($IncludeFieldEnvironment) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Environment\";\n\t\t\t\tvalue = $OctopusEnvironmentName;\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\n\n\n\t$IncludeFieldMachine = [boolean]::Parse($OctopusParameters['IncludeFieldMachine'])\n\tif ($IncludeFieldMachine) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Machine\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Machine.Name'];\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t$IncludeFieldTenant = [boolean]::Parse($OctopusParameters['IncludeFieldTenant'])\n\tif ($IncludeFieldTenant) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Tenant\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Deployment.Tenant.Name'];\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t\t$IncludeFieldUsername = [boolean]::Parse($OctopusParameters['IncludeFieldUsername'])\n\tif ($IncludeFieldUsername) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Username\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Deployment.CreatedBy.Username'];\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t$IncludeFieldRelease = [boolean]::Parse($OctopusParameters['IncludeFieldRelease'])\n\tif ($IncludeFieldRelease) {\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Release\";\n\t\t\t\tvalue = $OctopusReleaseNumber;\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\n\t\n\t\n\t$IncludeFieldReleaseNotes = [boolean]::Parse($OctopusParameters['IncludeFieldReleaseNotes'])\n\tif ($StatusInfo[\"success\"] -and $IncludeFieldReleaseNotes) {\n\t\n\t\t\n\t\t$link = $OctopusParameters['Octopus.Web.ReleaseLink'];\n\t\t$baseurl = $OctopusParameters['OctopusBaseUrl'];\n\t\t\n\t\t$notes = $OctopusReleaseNotes\n\t\t\n\t\tif ($notes.Length -gt 300) {\n\t\t\t$shortened = $OctopusReleaseNotes.Substring(0,300);\n\t\t\t$notes = \"$shortened `n `<${baseurl}${link}|view all changes`>\"\n\t\t}\n\t\t\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Changes in this release\";\n\t\t\t\tvalue = $notes;\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\n\t#failure fields\n\t\n\t$IncludeErrorMessageOnFailure = [boolean]::Parse($OctopusParameters['IncludeErrorMessageOnFailure'])\n\tif (-not $StatusInfo[\"success\"] -and $IncludeErrorMessageOnFailure) {\n\t\t\t\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"Error text\";\n\t\t\t\tvalue = $OctopusParameters['Octopus.Deployment.Error'];\n\t\t\t}\n\t\t;\t\n\t}\t\n\t\t\n\n\t$IncludeLinkOnFailure = [boolean]::Parse($OctopusParameters['IncludeLinkOnFailure'])\n\tif (-not $StatusInfo[\"success\"] -and $IncludeLinkOnFailure) {\n\t\t\n\t\t$link = $OctopusParameters['Octopus.Web.DeploymentLink'];\n\t\t$baseurl = $OctopusParameters['OctopusBaseUrl'];\n\t\n\t\t$fields += \n\t\t\t@{\n\t\t\t\ttitle = \"See the process\";\n\t\t\t\tvalue = \"`<${baseurl}${link}|Open process page`>\";\n\t\t\t\tshort = \"true\";\n\t\t\t}\n\t\t;\t\n\t}\n\t\n\t\n\treturn $fields;\n\t\n}\n\nfunction Slack-Rich-Notification ($Success)\n{\n $status_info = Slack-Populate-StatusInfo -Success $Success\n\t$fields = Slack-Populate-Fields -StatusInfo $status_info\n\n\t\n\t$payload = @{\n channel = $OctopusParameters['Channel']\n username = $OctopusParameters['Username'];\n icon_url = $OctopusParameters['IconUrl'];\n\t\t\n attachments = @(\n @{\n\t\t\t\tfallback = $status_info[\"fallback\"];\n\t\t\t\tcolor = $status_info[\"color\"];\n\t\t\t\n\t\t\t\tfields = $fields\n };\n );\n }\n\t\n\t#We unescape here to allow links in the Json, as ConvertTo-Json escapes <,> and other special symbols\n\t$json_body = ($payload | ConvertTo-Json -Depth 4 | % { [System.Text.RegularExpressions.Regex]::Unescape($_) });\n\t\n\t\n try {\n \t$invokeParameters = @{}\n $invokeParameters.Add(\"Method\", \"POST\")\n $invokeParameters.Add(\"Body\", $json_body)\n $invokeParameters.Add(\"Uri\", $OctopusParameters['HookUrl'])\n $invokeParameters.Add(\"ContentType\", \"application/json\")\n \n # Check for UseBasicParsing\n if ((Get-Command Invoke-RestMethod).Parameters.ContainsKey(\"UseBasicParsing\"))\n {\n # Add the basic parsing argument\n $invokeParameters.Add(\"UseBasicParsing\", $true)\n }\n\n \n [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n Invoke-RestMethod @invokeParameters\n \n } catch {\n echo \"Something occured\"\n echo $_.Exception\n echo $_\n #echo $json_body\n throw\n }\n \n}\n\n\n\n$success = ($OctopusParameters['Octopus.Deployment.Error'] -eq $null);\n\nSlack-Rich-Notification -Success $success\n",
99
"Octopus.Action.Script.Syntax": "PowerShell",
1010
"Octopus.Action.Script.ScriptSource": "Inline",
1111
"Octopus.Action.RunOnServer": "false",
@@ -169,11 +169,11 @@
169169
"Links": {}
170170
}
171171
],
172-
"LastModifiedOn": "2022-03-08T04:18:00.000+00:00",
173-
"LastModifiedBy": "twerthi",
172+
"LastModifiedOn": "2025-08-29T05:00:10.555Z",
173+
"LastModifiedBy": "benjimac93",
174174
"$Meta": {
175-
"ExportedAt": "2022-09-08T18:00:57.940Z",
176-
"OctopusVersion": "2022.2.8136",
175+
"ExportedAt": "2025-08-29T05:00:10.555Z",
176+
"OctopusVersion": "2025.3.12161",
177177
"Type": "ActionTemplate"
178178
},
179179
"Category": "slack"

0 commit comments

Comments
 (0)