slack notification
parent
7f5f554579
commit
9b4b0d22d8
@ -0,0 +1,63 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sending messages using Incoming Webhooks
|
||||
|
||||
.PARAMETER Url
|
||||
Required parameter. Incoming Webhook URL to post a message
|
||||
.PARAMETER ToolName
|
||||
Required parameter. The name of tool
|
||||
.PARAMETER ToolVersion
|
||||
Required parameter. Specifies the version of tool
|
||||
.PARAMETER PipelineUrl
|
||||
Required parameter. The pipeline URL
|
||||
.PARAMETER ImageUrl
|
||||
Optional parameter. The image URL
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.Uri]$Url,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]$ToolName,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]$ToolVersion,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[System.String]$PipelineUrl,
|
||||
|
||||
[System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'
|
||||
)
|
||||
|
||||
# Import helpers module
|
||||
Import-Module $PSScriptRoot/slack.helpers.psm1 -DisableNameChecking
|
||||
|
||||
# Create JSON body
|
||||
$text = "The following versions of '$toolName' are available to upload: $toolVersion\nLink to the pipeline: $pipelineUrl"
|
||||
$jsonBodyMessage = @"
|
||||
{
|
||||
"blocks": [
|
||||
{
|
||||
"type": "section",
|
||||
"text": {
|
||||
"type": "mrkdwn",
|
||||
"text": "$text"
|
||||
},
|
||||
"accessory": {
|
||||
"type": "image",
|
||||
"image_url": "$imageUrl",
|
||||
"alt_text": "$toolName"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"@
|
||||
|
||||
# Send Slack message
|
||||
$null = Send-SlackPostMessageIncomingWebHook -Uri $url -Body $jsonBodyMessage
|
||||
Write-Host "Message template: `n $jsonBodyMessage"
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue