Last active
February 18, 2017 19:18
-
-
Save whereisaaron/6f7dbec27157f5ee30c3810d0d6f8783 to your computer and use it in GitHub Desktop.
Octopus Deploy Slack Notification Step Template
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
{ | |
"Id": "ActionTemplates-81", | |
"Name": "Slack - Notify Deployment", | |
"Description": "Notifies Slack of deployment status. Uses the Octopus Deploy system variable to determine whether a deployment was successful.", | |
"ActionType": "Octopus.Script", | |
"Version": 1, | |
"Properties": { | |
"Octopus.Action.Script.ScriptBody": "function Slack-Rich-Notification ($notification)\n{\n $payload = @{\n channel = $OctopusParameters['Channel']\n username = $OctopusParameters['Username'];\n icon_url = $OctopusParameters['IconUrl'];\n attachments = @(\n @{\n fallback = $notification[\"fallback\"];\n color = $notification[\"color\"];\n fields = @(\n @{\n title = $notification[\"title\"];\n title_link = $notification[\"title_link\"];\n value = $notification[\"value\"];\n });\n };\n );\n }\n\n Invoke-RestMethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['HookUrl'] -ContentType 'application/json'\n}\n\n$IncludeMachineName = [boolean]::Parse($OctopusParameters['IncludeMachineName']);\nif ($IncludeMachineName) {\n $MachineName = $OctopusParameters['Octopus.Machine.Name'];\n if ($MachineName) {\n $FormattedMachineName = \"($MachineName)\";\n }\n}\n\nif ($OctopusParameters['Octopus.Deployment.Error'] -eq $null){\n Slack-Rich-Notification @{\n title = \"Success\";\n title_link = \"$OctopusWebBaseUrl$OctopusWebDeploymentLink\";\n value = \"Deploy <$OctopusWebBaseUrl$OctopusWebProjectLink|$OctopusProjectName> release <$OctopusWebBaseUrl$OctopusWebReleaseLink|$OctopusReleaseNumber> to $OctopusEnvironmentName $OctopusActionTargetRoles $OctopusDeploymentTenantName $FormattedMachineName\";\n fallback = \"Deployed $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName successfully\";\n color = \"good\";\n };\n} else {\n Slack-Rich-Notification @{\n title = \"Failed\";\n title_link = \"$OctopusWebBaseUrl$OctopusWebDeploymentLink\";\n value = \"Deploy <$OctopusWebBaseUrl$OctopusWebProjectLink|$OctopusProjectName> release <$OctopusWebBaseUrl$OctopusWebReleaseLink|$OctopusReleaseNumber> to $OctopusEnvironmentName $OctopusActionTargetRoles $OctopusDeploymentTenantName $FormattedMachineName\";\n fallback = \"Failed to deploy $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName\";\n color = \"danger\";\n };\n}", | |
"Octopus.Action.Script.Syntax": "PowerShell", | |
"Octopus.Action.Package.NuGetFeedId": "feeds-builtin", | |
"Octopus.Action.Script.ScriptSource": "Inline", | |
"Octopus.Action.RunOnServer": "false" | |
}, | |
"Parameters": [ | |
{ | |
"Name": "HookUrl", | |
"Label": "Webhook URL", | |
"HelpText": "The Webhook URL provided by Slack, including token.", | |
"DefaultValue": null, | |
"DisplaySettings": {} | |
}, | |
{ | |
"Name": "Channel", | |
"Label": "Channel handle", | |
"HelpText": "Which Slack channel to post notifications to.", | |
"DefaultValue": null, | |
"DisplaySettings": {} | |
}, | |
{ | |
"Name": "IconUrl", | |
"Label": "Icon URL", | |
"HelpText": "The icon to use for this user in Slack", | |
"DefaultValue": "http://octopusdeploy.com/content/resources/favicon.png", | |
"DisplaySettings": {} | |
}, | |
{ | |
"Name": "Username", | |
"Label": null, | |
"HelpText": "The username shown in Slack against these notifications", | |
"DefaultValue": "Octopus Deploy", | |
"DisplaySettings": {} | |
}, | |
{ | |
"Name": "IncludeMachineName", | |
"Label": "Include machine name", | |
"HelpText": "Should machine name be included in notification to Slack?", | |
"DefaultValue": "True", | |
"DisplaySettings": { | |
"Octopus.ControlType": "Checkbox" | |
} | |
} | |
], | |
"$Meta": { | |
"ExportedAt": "2017-02-18T19:11:12.785Z", | |
"OctopusVersion": "3.3.2", | |
"Type": "ActionTemplate" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is based on jgbrights example with tweaks and some links added.