How to Tweet Azure Pipeline activity easily

category: [ VSTS / TFS ] tags: [ AzureDevOps ] [ Web Online Tools ]
created: 20 Sep 2018 @ 00:14 modified: 20 Sep 2018 @ 01:21


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://beeming.net/
  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://beeming.net/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://beeming.net/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.

ABOUT ME

Gordon Beeming works at Nologo Studios in the sunny city of Durban, South Africa. He is the Lead for the Data and Services Team and has a strong focus on Developer Efficiencies and R&D. When he's not hacking away at a keyboard in Visual Studio he'll generally be relaxing with his family or hitting the black top getting in some mileage. He is a Visual Studio ALM Ranger and Visual Studio ALM MVP.

Follow me on Strava

TOOLS

I plan on writing a bunch of online tools and sharing the code for how I made those tools. If you have any feedback you can ping me on Twitter (@GordonBeeming) or mail me [email protected].