Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save themindfulcoder/adcf8480ae40ae170c2f8d57c2e854fb to your computer and use it in GitHub Desktop.
Save themindfulcoder/adcf8480ae40ae170c2f8d57c2e854fb to your computer and use it in GitHub Desktop.
A power shell script that sends a slack notification from a octopus deployment step
Set-StrictMode -Version Latest
$proxy = 'http://127.0.0.1:8080'
$apiKey = "###APIKEY###"
$uri = "https://hooks.slack.com/services/" + $apiKey
$deploymentEnvironment = $OctopusParameters["Octopus.Environment.Name"]
$deployByWho = $OctopusParameters["Octopus.Deployment.CreatedBy.DisplayName"]
$deployErrorDetail = $OctopusParameters["Octopus.Deployment.ErrorDetail"]
$deploymentVersion = $OctopusParameters["Octopus.Release.CurrentForEnvironment.Number"]
$deploymentVersion = $deploymentVersion + " -> "
$deploymentVersion = $deploymentVersion + $OctopusParameters["Octopus.Release.Number"]
$emoji = ":smile:"
$channel = "#general"
$username = "OctoBot"
$text = "$deploymentEnvironment ($deploymentVersion)`rby $deployByWho"
$text = $text + "`rError: $deployErrorDetail"
$payload = @{
"channel" = $channel
"icon_emoji" = $emoji
"text" = $text
"username" = $username
"link_names" = 1
}
$body = (ConvertTo-Json -Compress -InputObject $payload)
Invoke-WebRequest -Method Post -UseBasicParsing -Body $body -Proxy $proxy -Uri $uri | Out-Null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment