If you weren’t able to attend //Build or Ignite last month, hopefully you’ve had the chance to watch some of the recorded sessions on the great new features coming to Microsoft’s suites of products. Personally, the two I’m most excited about are Visual Studio Online (VSO) and Azure Automation. These two services will be of great assistance in your Application Lifecycle Management (ALM)/DevOps journey.
Of all the current and soon to be released features in VSO, what’s caught my eye lately are the extensibility options. One option announced last year is Service Hooks. Service Hooks let you perform tasks on other services when something happens in a VSO project (e.g. new build created, work item updated, etc.). One of the available services is a Webhook. A Webhook can post JSON data about the event from VSO to any URL of your choice. Enter Azure Automation!
With the recent announcement of Azure Automation Webhooks, you can trigger a custom runbook hosted in Azure to perform any action you want when an event happens in VSO. Is that not awesome!? Think of the possibilities this could open for your DevOps ambitions!
Creating a Webhook and VSO Service Hook
To show you how this works, I created a Runbook in Azure Automation that will receive data from VSO and email it out (via O365) to the addresses specified. Here are the steps to set up this runbook.
- Browse to http://portal.azure.com and login to your organization’s Azure subscription. From here, click on Browse –> Automation Accounts.
- On the Automation Accounts blade, you can choose to create a new account or put the Runbook in an existing Automation Account.
- From the Automation Account, click on Assets –> Credentials. Create a new credential containing the username/password of the user you’d like to have send the email. Make note of the name you assign to the credential.
- Browse to Microsoft Script Center and download the Send-VsoEmail runbook.
- Open the script and find the “Manually configured variables” section on line #27. Make the following changes per your environment:
- Line #28 – Update the credential asset name to what you set up in Step #3.
- Line #29 – Update the array of email addresses that will be added to the To field of the email.
- Line #30 – Update the SMTP server you wish to use.
- Browse back to the Automation Account and from there, click Add a runbook –> Import an existing runbook. Select the file you modified from Step #5 and it will create the Send-VsoEmail Runbook.
NOTE: The runbook will be created with the same name as the file. If you would like to use a different name, simply rename the file before importing.
- You should now have a Runbook in your environment that looks like this.
- Next, we need to create a Webhook in Azure Automation, allowing us to kick off this Runbook from VSO. From the Send-VsoEmail Runbook, click on Webhooks –> Create new webhook. We now have a Webhook that allows us to call that Runbook from VSO (or really anywhere for that matter).
NOTE: Make sure you save the URL, because once you click Create, there is no way to retrieve it again.
- Browse to your Visual Studio Online account and the project you wish to integrate with. From the project home page, click on the gear in the top-right corner.
- From the control panel page, click on the Service Hooks tab. Then create a new Web Hook subscription.
- Set the Trigger value to Work item created. You can build integrations off any of the events listed but we’ll use this one for our purposes.
- In the URL field, enter the Webhook URL created from Step #8. You have the option to configure additional settings, but for our purpose we’ll configure it as shown below Then click Test.
NOTE: For our email to pull the data correctly, you must at a minimum send the Resource details.
- When you click Test, it will send test data to our Azure Automation Runbook via the Webhook. Assuming everything is OK, you should get a success message like below.
- Since our test is a live test that actually starts the runbook, you should receive an email containing the test VSO data.
- To conclude our test, let’s create a real VSO work item and make sure it works. Browse to the Backlog view of your VSO project and create a new Work Item.
- We should now get a new email, notifying us of the new backlog item that was created!
And there you have it! You now have the power to build all sorts of cool integrations using Visual Studio Online Service Hooks, but that’s not all! VSO is just one example of the many integration possibilities of using Webhooks. This functionality could work easily with other applications like GitHub, Azure Scheduler or really any custom application. Well done!