Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. param([string]$buildNumber="NotSet", [string]$buildId="NotSet", [string]$branch="NotSet", [string]$buildName="NoSet", [string]$buildBy="NoSet")
  2.  
  3. # PRINT PASSED VARS
  4. #=======================================================================
  5. Write-Host "Triggering Slack Build Notification...";
  6. Write-Host " - Build Number: $buildNumber";
  7. Write-Host " - Build Id: $buildId";
  8. Write-Host " - Build Name: $buildName";
  9. Write-Host " - Branch: $branch";
  10. Write-Host " - By: $buildBy";
  11.  
  12. # VARIABLES
  13. #=======================================================================
  14. $urlString = 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXX';
  15. $channel = '#SLACKCHANNELNAME';
  16. $userName = 'TFSBUILD';
  17. $userImage = 'http://i.imgur.com/23ycZ8A.png';
  18.  
  19. # DEFINE FIELD ARRY
  20. #=======================================================================
  21. [Array] $fields = @(
  22.     @{ title="Build Definition"; value=$buildName; short='false'; }
  23.     @{ title="Branch"; value=$branch; short='false'; }
  24.     @{ title="Requested by"; value=$buildBy; short='false'; }
  25. )
  26.  
  27. # CREATE BODY
  28. #=======================================================================
  29. $postParams = @{
  30.     channel = $channel
  31.     username = $userName
  32.     icon_url = $userImage;
  33.     as_user = 'false'
  34.     text = 'Build <http://rddevtfs1:8080/tfs/DefaultCollection/HiFx/_build#_a=summary&buildId=' + $buildId + '|Build ' + $buildNumber + '> started';
  35.     attachments = @(
  36.         @{
  37.             color = "#e3e4e6";
  38.             fields = $fields;
  39.         };
  40.     );
  41. }
  42.  
  43. $json = $postParams | ConvertTo-Json -Depth 4
  44. $json = [regex]::replace($json,'\\u[a-fA-F0-9]{4}',{[char]::ConvertFromUtf32(($args[0].Value -replace '\\u','0x'))})
  45. $json = $json -replace "\\\\", "\"
  46.  
  47. # EXECUTE
  48. #=======================================================================
  49. Invoke-WebRequest -Uri $urlString -Method POST -Body $json
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement