Created
November 6, 2017 15:16
-
-
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
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
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