Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param([string]$buildNumber="NotSet", [string]$buildId="NotSet", [string]$branch="NotSet", [string]$buildName="NoSet", [string]$buildBy="NoSet")
- # PRINT PASSED VARS
- #=======================================================================
- Write-Host "Triggering Slack Build Notification...";
- Write-Host " - Build Number: $buildNumber";
- Write-Host " - Build Id: $buildId";
- Write-Host " - Build Name: $buildName";
- Write-Host " - Branch: $branch";
- Write-Host " - By: $buildBy";
- # VARIABLES
- #=======================================================================
- $urlString = 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXX';
- $channel = '#SLACKCHANNELNAME';
- $userName = 'TFSBUILD';
- $userImage = 'http://i.imgur.com/23ycZ8A.png';
- # DEFINE FIELD ARRY
- #=======================================================================
- [Array] $fields = @(
- @{ title="Build Definition"; value=$buildName; short='false'; }
- @{ title="Branch"; value=$branch; short='false'; }
- @{ title="Requested by"; value=$buildBy; short='false'; }
- )
- # CREATE BODY
- #=======================================================================
- $postParams = @{
- channel = $channel
- username = $userName
- icon_url = $userImage;
- as_user = 'false'
- text = 'Build <http://rddevtfs1:8080/tfs/DefaultCollection/HiFx/_build#_a=summary&buildId=' + $buildId + '|Build ' + $buildNumber + '> started';
- attachments = @(
- @{
- color = "#e3e4e6";
- fields = $fields;
- };
- );
- }
- $json = $postParams | ConvertTo-Json -Depth 4
- $json = [regex]::replace($json,'\\u[a-fA-F0-9]{4}',{[char]::ConvertFromUtf32(($args[0].Value -replace '\\u','0x'))})
- $json = $json -replace "\\\\", "\"
- # EXECUTE
- #=======================================================================
- Invoke-WebRequest -Uri $urlString -Method POST -Body $json
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement