Call a WebHook from Inline Powershell

Tips and tricks Inline Powershell task VSTS, call a webhook from your build task

Maximize how you use your VSTS build and release pipeline with Inline Powershell tasks. In this blog series ‘Tips and Tricks for Inline Powershell’, I will show simple samples on how to get more out of your pipelines. This blog post: Call WebHooks from your build pipeline

VSTS Inline Powershell task
The Inline PowerShell VSTS task enables you to execute PowerShell from a textbox within your build or release pipeline. You can run a PowerShell script on you agent or as Azure Powershell.
Introduction Inline Powershell Task
Install Inline Powershell Task

Call a WebHook
Many systems can be integrated with a WebHooks. A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. A web application implementing WebHooks will POST a message to a URL when certain things happen. You can do this at any time in you build or release pipeline.

Services like Sendgrid, Slack or mayby the application you are developing have standard incoming WebHooks where you can integrate. You can do the Post with the Invoke-WebRequest Powershell command. Forexample the following script will post a message in the random slack channel:

$payload = @{
 "channel" = "#random"
  "text" = "This is my message. Hello there!"
  "username"= "monkey-bot"
  "icon_emoji"= ":monkey_face:"

Invoke-WebRequest -UseBasicParsing `
 -Body (ConvertTo-Json -Compress -InputObject $payload) `
 -Method Post `
 -Uri ""

Replace the T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX with your own configuration keys. Enable a incoming WebHook in Slack.

More tips and tricks
Use VSTS variables
Let your task fail
Set progress
Change buildnumber
VSTS Command overview
Call a WebHook
Download a file
Install a Powershell Module
Navigate VSTS as filesystem
Make VSTS API Rest calls
Script example: Act on failed build

Invoke-WebRequest use basic parsing
When calling the Invoke-WebRequest you need to add the parameter -UseBasicParsing because the Internet Explorer engine is not configured on the build server. If you do not add that parameter you will see the following error:

The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.

2 thoughts on “Call a WebHook from Inline Powershell”

  1. Thank you for the post, Is it possible to send a yammer notification from vNext build definition in TFS ? if yes-could you please provide any support document or information.

    Thank you in advance


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.