mirror of
https://github.com/actions/versions-package-tools.git
synced 2026-01-10 21:51:11 +08:00
slack notification
This commit is contained in:
38
slack-notification/slack.helpers.psm1
Normal file
38
slack-notification/slack.helpers.psm1
Normal file
@@ -0,0 +1,38 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sending messages using Incoming Webhooks
|
||||
https://api.slack.com/messaging/webhooks
|
||||
#>
|
||||
|
||||
function Send-SlackPostMessageIncomingWebHook
|
||||
{
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Uri]$Uri,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Object]$Body
|
||||
)
|
||||
|
||||
try
|
||||
{
|
||||
$response = Invoke-RestMethod -Uri $uri -Method POST -Body $body -ErrorAction Stop
|
||||
if ($response -eq 'ok')
|
||||
{
|
||||
return $response
|
||||
}
|
||||
else
|
||||
{
|
||||
Write-Host "##vso[task.LogIssue type=error;] Something went wrong. Response is '$response'"
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Write-Host "##vso[task.LogIssue type=error;] Slack send post message failed: '$_'"
|
||||
}
|
||||
|
||||
Write-Host "##vso[task.complete result=Failed;]"
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user