Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions step-templates/slack-detailed-notification.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"Name": "Slack - Detailed Notification",
"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.",
"ActionType": "Octopus.Script",
"Version": 10,
"Version": 11,
"Properties": {
"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",
"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",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
Expand Down Expand Up @@ -169,11 +169,11 @@
"Links": {}
}
],
"LastModifiedOn": "2022-03-08T04:18:00.000+00:00",
"LastModifiedBy": "twerthi",
"LastModifiedOn": "2025-08-29T05:00:10.555Z",
"LastModifiedBy": "benjimac93",
"$Meta": {
"ExportedAt": "2022-09-08T18:00:57.940Z",
"OctopusVersion": "2022.2.8136",
"ExportedAt": "2025-08-29T05:00:10.555Z",
"OctopusVersion": "2025.3.12161",
"Type": "ActionTemplate"
},
"Category": "slack"
Expand Down