-
Notifications
You must be signed in to change notification settings - Fork 506
Expand file tree
/
Copy pathslack-detailed-notification.json
More file actions
180 lines (180 loc) · 11.7 KB
/
slack-detailed-notification.json
File metadata and controls
180 lines (180 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{
"Id": "07d64408-ac47-490e-ade2-01bab607ed4f",
"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": 12,
"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$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 \n\t\t$link = $OctopusParameters['Octopus.Web.ReleaseLink'];\n\t\t$baseurl = $OctopusParameters['OctopusBaseUrl'];\n\t\t\n\t\t# Handle double quotes in the notes\n $notes = $OctopusParameters['Octopus.Release.Notes'].Replace(\"`\"\", \"\\\"\"\")\n\t\t\n\t\tif ($notes.Length -gt 300) {\n\t\t\t$shortened = $notes.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\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",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.FeedId": null,
"Octopus.Action.Package.PackageId": null
},
"Parameters": [
{
"Id": "635cd97f-f3aa-48a5-a165-839650921931",
"Name": "HookUrl",
"Label": "Webhook URL",
"HelpText": "The Webhook URL provided by Slack, including token.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Sensitive"
},
"Links": {}
},
{
"Id": "14f5203e-4ce2-4ea2-ae25-379ef538e18b",
"Name": "Channel",
"Label": "Channel handle",
"HelpText": "Which Slack channel to post notifications to.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "1ab73186-ab66-4be6-818f-f53a39f3f962",
"Name": "IconUrl",
"Label": "Icon URL",
"HelpText": "The icon to use for this user in Slack",
"DefaultValue": "https://octopus.com/content/resources/favicon.png",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "a746df23-8cd6-4084-8aea-3713b68b6ec5",
"Name": "Username",
"Label": "",
"HelpText": "The username shown in Slack against these notifications",
"DefaultValue": "Octopus Deploy",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "b4918796-8fed-4074-bd3b-f84b555d1015",
"Name": "DeploymentInfoText",
"Label": "Main message",
"HelpText": "Long information message shown in slack. This message is prefixed with \"Deployed successfully\" or \"Failed to deploy\" depending on status.",
"DefaultValue": "#{Octopus.Project.Name} release #{Octopus.Release.Number} to #{Octopus.Environment.Name} (#{Octopus.Machine.Name})",
"DisplaySettings": {
"Octopus.ControlType": "MultiLineText"
},
"Links": {}
},
{
"Id": "60e51e4a-2741-4a36-aaf2-e040c19929d9",
"Name": "IncludeFieldRelease",
"Label": "Include release number field",
"HelpText": "Shows short field with release number name",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "6b383bdb-10b4-4e8b-bf8a-d4c257b0731b",
"Name": "IncludeFieldReleaseNotes",
"Label": "Include release notes Field",
"HelpText": "Release notes are only included on successful deployment",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "df788f61-b026-47da-8a0d-d79e8e48ea4c",
"Name": "IncludeFieldMachine",
"Label": "Include machine name field",
"HelpText": "Shows short field with machine name",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "7a88c0ce-9bd0-4ad3-af76-1d71c1d4f6e4",
"Name": "IncludeFieldEnvironment",
"Label": "Include environment name field",
"HelpText": "Shows short field with environment name",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "f25651aa-920c-4894-b2c6-a4a4c1c6a44d",
"Name": "IncludeFieldTenant",
"Label": "Include tenant name field",
"HelpText": "Shows short field with name of tenant",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "a929f109-b4ae-40f0-b5e5-b15c448ff672",
"Name": "IncludeFieldUsername",
"Label": "Include username field",
"HelpText": "Shows the username of user that initiated deployment",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "3bbe0522-ef27-4793-b249-c87242c818fb",
"Name": "IncludeLinkOnFailure",
"Label": "Include deployment process link on failure",
"HelpText": "When deployment failed a link \"Open process page\" is added to the notification pointing to deployment process page",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "d68b3d72-2944-4f57-bcb9-a96b388c5d0d",
"Name": "IncludeErrorMessageOnFailure",
"Label": "Include error message text on failure",
"HelpText": "When deployment failed error text is shown as part of notification",
"DefaultValue": "false",
"DisplaySettings": {
"Octopus.ControlType": "Checkbox"
},
"Links": {}
},
{
"Id": "9672e4ab-fe66-4351-bf9b-78cac354d7b6",
"Name": "OctopusBaseUrl",
"Label": "Octopus base url",
"HelpText": "Base URL to add to the links in the notification. If octopus server dashboard is at \"http://octopus/app\" include all before the \"app\" part (\"http://octopus\").",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
}
],
"LastModifiedOn": "2026-02-24T01:28:50.335Z",
"LastModifiedBy": "twerthi",
"$Meta": {
"ExportedAt": "2026-02-24T01:28:50.335Z",
"OctopusVersion": "2025.4.10453",
"Type": "ActionTemplate"
},
"Category": "slack"
}