Created
August 17, 2016 08:20
-
-
Save lazytesting/44274a0fdef5fc033598ed8eb5d8a6ea to your computer and use it in GitHub Desktop.
notify slack on failed teamcity build
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 Test-TeamCityBuildStatus | |
{ | |
param | |
( | |
[string] $ServerUrl ="[TC server url]", | |
[string] $UserName = "[tc user]", | |
[string] $Password = "[TC password]", | |
[string] $BuildTypeId = "[build id]" | |
) | |
try | |
{ | |
$client = New-Object System.Net.WebClient | |
$client.Credentials = New-Object System.Net.NetworkCredential $UserName, $Password | |
$url = "$ServerUrl/httpAuth/app/rest/buildTypes/id:$BuildTypeId/builds/canceled:false/status" | |
$status = $client.DownloadString($url) | |
if ($status -ne "SUCCESS") | |
{ | |
return $false | |
} | |
else | |
{ | |
$url = "$ServerUrl/httpAuth/app/rest/buildTypes/id:$buildTypeId/builds/canceled:false,running:any/status" | |
$status = $client.DownloadString($url) | |
$status -eq "SUCCESS" | |
} | |
} | |
catch | |
{ | |
return $null | |
} | |
} | |
function Notify-Slack($payload) | |
{ | |
Invoke-WebRequest ` | |
-Uri "[SLACK HOOK URL]" ` | |
-Method "POST" ` | |
-Body (ConvertTo-Json -Compress -InputObject $payload) | |
} | |
$result = Test-TeamCityBuildStatus; | |
if (!$result) | |
{ | |
$payload = @{ | |
"channel" = "[#Channel]"; | |
"icon_emoji" = ":bomb:"; | |
"text" = "<!channel> Deployment to CI has failed!!!"; | |
"username" = "Teamcity";} | |
Notify-Slack -payload $payload | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment