public/Send-BuildStopMessage.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function Send-BuildStopMessage {
    [CmdletBinding()]
    param(
        [string[]]$BuildTask
    )

    $buildTaskString = ($BuildTask -join ', ')

    $primaryAttachment = @{
        Text = "Notify List: $(Get-BuildNotifyList)"
    }
    
    if ($script:failedTask) {
        $message = Get-BuildMessage -StopFailed

        $primaryAttachment.Color = '#FF0000'
        $primaryAttachment.Title = ":bomb: Build Failed: $buildTaskString"
        $primaryAttachment.Fallback = "Build Failed: $buildTaskString"
    }
    else {
        $message = Get-BuildMessage -StopSuccess

        $primaryAttachment.Color = '#228B22' 
        $primaryAttachment.Title = ":thumbsup: Finished Build: $buildTaskString"
        $primaryAttachment.Fallback = "Finished Build: $buildTaskString"
    }

    $null = New-SlackMessageAttachment @primaryAttachment |
        New-SlackMessage @message |
        Send-SlackMessage
}