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 .
Before I get started with the how, let's discuss the why
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
@GordonBeeming BeemingBlogCore - WebApp - CD: Deployment of release Release-89 on stage PROD succeeded. Time to deploy: 00:00:52. https://t.co/8tMe50NiMt
— My Pipelines (@MyPipelines) September 19, 2018
It would be great if this service is used by a lot of projects but I guess we'll see how that goes , 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
- Browsing to https://gordonbeeming.com/blog/
- Clicking on online tools in the right navigation
Next click on My API Keys
You'll now be asked to login if you aren't already or just register as a new user if you not registered
Once logged in you can click create
Enter the form fields
- Comment - This is just for your reference and doesn't get used
- Handle - Yours or your projects Twitter handle, if you don't want to me mentioned you can leave it blank
- Tags - What tags do you want to use when tweeting that a build or release has completed
- 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
- Click Create
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.
That's all for creating a key
Creating web hooks in Azure DevOps
The steps for creating builds and releases are the same, just the forms vary slightly. Start off by
- Opening project settings from your project
- Clicking on Service hooks
- Clicking on Create subscription
When the dialog opens scroll down to Web Hooks and click Next
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
- Make sure Build completed is selected
- 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
- Choose what statuses you want this web hook to trigger for
- Click Next
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.
After that is al set you can go ahead and click Test. The dialog will think for a bit and then should show succeeded
Lastly click Close on that dialog and Finish on the main dialog.
Your web hook is created.
Web hook for a completed releases
In the Trigger window
- Make sure Release deployment completed is selected
- 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
- If a specific pipeline was selected you'll be given the option to select which environment to trigger for
- Choose what statuses you want this web hook to trigger for
- Click Next
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.
As with the build web hook you can click Test to verify and afterwards click Close and Finish on the above dialog.
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 .