How to Tweet Azure Pipeline activity easily

A while back I created a service linked to Twitter that tweets when your pipeline has completed in Azure Pipelines. This post is going to show you how you can easily tweet when your builds complete .
📅 20 Sep 2018

A while back I created a service linked to Twitter that tweets when your pipeline has completed in Azure Pipelines. This post is going to show you how you can easily tweet when your builds complete Smile.

Before I get started with the how, let's discuss the why Smile

Why did I create this service?

With the announcement of unlimited build minutes and 10 parallel pipelines for open source projects there will be a lot more open source projects using Azure Pipelines. My thinking is it would be nice for an open project to expose deployments and private releases easier. That's where this service comes in. As an owner of a project you can setup web hooks in Azure DevOps and this service will send a tweet to your Twitter handle and optionally add extra #Tags that your users would generally be following for your project. You'll get something like below

It would be great if this service is used by a lot of projects but I guess we'll see how that goes Smile, worst case I've got my projects and it was a good experiment.

Creating an API Key

To create an api key you'd need to start off by

  1. Browsing to https://gordonbeeming.com/blog/
  2. Clicking on online tools in the right navigation

image

Next click on My API Keys

image

You'll now be asked to login if you aren't already or just register as a new user if you not registered Open-mouthed smile

image

Once logged in you can click create

image

Enter the form fields

  1. Comment - This is just for your reference and doesn't get used
  2. Handle - Yours or your projects Twitter handle, if you don't want to me mentioned you can leave it blank Smile
  3. Tags - What tags do you want to use when tweeting that a build or release has completed
  4. Expire Date - How long do you want this key to be valid for, by default it uses 3 months but you can make that as long as you'd like
  5. Click Create

image

Now you'll be redirected to the Edit view. Copy the api key, it's important. Because none of your data can be accessed with the key we leave it in the edit view for if you forget it and come back later. If this key is used in future to access the data in anyway this will change.

image

That's all for creating a key Smile

Creating web hooks in Azure DevOps

The steps for creating builds and releases are the same, just the forms vary slightly. Start off by

  1. Opening project settings from your project
  2. Clicking on Service hooks
  3. Clicking on Create subscription

image

When the dialog opens scroll down to Web Hooks and click Next

image

That small step should be used if you doing a build or release web hook.

Web hook for a completed build

In the Trigger window

  1. Make sure Build completed is selected
  2. Specify a specific pipeline that you want this web hook to be for or leave as [Any] if you want all to trigger the web hook
  3. Choose what statuses you want this web hook to trigger for
  4. Click Next

image

In the Action window enter the Url as https://gordonbeeming.com/blog/api/azure-devops-hooks/build-completed and the HTTP headers as "apikey:<your api key>". You can play with the amount of resource details to send if you want as well. We pull various pieces out as you could see above, from the html block for example we pull the build location so that it's easy for someone to browse to that end point.

image

After that is al set you can go ahead and click Test. The dialog will think for a bit and then should show succeeded Smile

imageimage

Lastly click Close on that dialog and Finish on the main dialog.

image

Your web hook is created.

Web hook for a completed releases

In the Trigger window

  1. Make sure Release deployment completed is selected
  2. Specify a specific pipeline that you want this web hook to be for or leave as [Any] if you want all to trigger the web hook
  3. If a specific pipeline was selected you'll be given the option to select which environment to trigger for
  4. Choose what statuses you want this web hook to trigger for
  5. Click Next

image

In the Action window enter the Url as https://gordonbeeming.com/blog/api/azure-devops-hooks/release-deployment-completed and the HTTP headers as "apikey:<your api key>". You can play with the amount of resource details to send if you want as well. We pull various pieces out as you could see above, from the html block for example we pull the build location so that it's easy for someone to browse to that end point.

image

As with the build web hook you can click Test to verify and afterwards click Close and Finish on the above dialog.

image

Your release web hook is now created and when it runs for matching criteria in your web hook you should see something out on Twitter

Future plans

I'm thinking that if this is a useful service and widely used I'll mature the setup to Azure Functions and probably allow users to bring their own AppId and AppSecrets to be able to Tweet as their own account, who knows I might need to introduce that feature due to abuse on this one. Another idea is support more web hook triggers if that's something people want.

Let's see how it goes and feedback and ideas is very welcome Smile.