Last active
January 17, 2019 11:06
-
-
Save jiimaho/106efaa6193e7aeac3100d5427a591ce to your computer and use it in GitHub Desktop.
Octopus script template for slack notifiation with release notes and deployment link
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
function Slack-Rich-Notification ($notification) | |
{ | |
$payload = @{ | |
channel = $OctopusParameters['Channel'] | |
username = $OctopusParameters['Username']; | |
icon_url = $OctopusParameters['IconUrl']; | |
attachments = @( | |
@{ | |
fallback = $notification["fallback"]; | |
color = $notification["color"]; | |
fields = @( | |
@{ | |
title = $notification["title"]; | |
value = $notification["value"]; | |
}); | |
}; | |
); | |
} | |
Invoke-RestMethod -Method POST -Body ($payload | ConvertTo-Json -Depth 4) -Uri $OctopusParameters['HookUrl'] -ContentType 'application/json' | |
} | |
$IncludeMachineName = [boolean]::Parse($OctopusParameters['IncludeMachineName']); | |
if ($IncludeMachineName) { | |
$MachineName = $OctopusParameters['Octopus.Machine.Name']; | |
$FormattedMachineName = "($MachineName)"; | |
} | |
$OctopusReleaseNotes = $OctopusParameters['Octopus.Release.Notes']; | |
$OctopusRelativeDeploymentLink = $OctopusParameters['Octopus.Web.DeploymentLink']; | |
$FullDeployUrl = "https://your-octopus-url.com$OctopusRelativeDeploymentLink" | |
if ($OctopusParameters['Octopus.Deployment.Error'] -eq $null){ | |
Slack-Rich-Notification @{ | |
title = "Success"; | |
value = "Deployed $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName $FormattedMachineName. $OctopusReleaseNotes. <$FullDeployUrl|See deploy>"; | |
fallback = "Deployed $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName successfully. $OctopusReleaseNotes. <$FullDeployUrl|See deploy>"; | |
color = "good"; | |
}; | |
} else { | |
Slack-Rich-Notification @{ | |
title = "Failed"; | |
value = "Deployed $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName $FormattedMachineName. $OctopusReleaseNotes. <$FullDeployUrl|See deploy>"; | |
fallback = "Failed to deploy $OctopusProjectName release $OctopusReleaseNumber to $OctopusEnvironmentName. $OctopusReleaseNotes. <$FullDeployUrl|See deploy>"; | |
color = "danger"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment