Elgato Stream Deck is a fancy USB device that can be used to control lights, OBS and many other things. It has wide range of plugins, which can be installed easily from Stream Deck Store. Currently the plugin store does not contain any plugins to use AzureDevOps, so of course I had to fix this shortcoming.
How to create Stream Deck plugin
The Stream Deck has plugin SDK’s for multiple languages like JavaScript, C++ and Objective-C. From those options the JavaScript is only language that I can write well, but I still wanted to have better development experience and searched for the C# SDK. Luckily there is a plugin template for .NET Core available in GitHub https://github.com/FritzAndFriends/StreamDeckToolkit/, that is easy to use and it has counter button example which can be easily modified and extended.
The template is installed simply by running dotnet new -i StreamDeckPluginTemplate command in Windows terminal. This command installs the .NET template that can be used by running command dotnet new streamdeck-plugin –plugin-name (projectname) –uuid (your uuid) –skipRestore false
For UUID I used my blog URL and added the project name “Azure DevOps Runner” into it. After creating the new project, it can be opened with Visual Studio and build without any extra hassle. I found really good tutorial from YouTube, that shows how to create plugins with C# and you should definitely check it out if you are creating your own plugin.
Interact with Azure Devops
To interact with AzureDevops we need some NuGet packages that will make things more easier. I usually use the Microsofts TeamFoundationServer packages that are really easy to use. In this project I used following packages:
- microsoft.visualstudio.services.client
- microsoft.teamfoundationserver.client
- microsoft.teamfoundationserver.extendedclient
In this plugin I decided to use the PAT token to access the AzureDevOps API’s. The PAT token is simple and has good security features like recycling and permissions, so it is perfectly suitable for this project. The connection into AzureDevOps is created with VssConnection class, that requires the authentication credentials. For PAT we need to create VssBasicCredentials with empty username.
var credentials = new VssBasicCredential(string.Empty, SettingsModel.PAT); var connection = new VssConnection(new Uri($"https://dev.azure.com/{SettingsModel.OrganizationName}"), credentials);
I’m using the SettingsModel to fetch all variables from Stream Deck configuration. This means that when the user is adding the button into Stream Deck, he or she has to put the PAT, organization name and few others settings in place. I have also hard coded the URL into newer dev.azure.com format, because everyone should already use it over the the old VSTS URL.
The build triggering is done by using the BuildHttpClient and ProjectHttpClient. BuildHttpClient can trigger the build, but it needs the build and project definitions, which needs to be fetched first. Both clients can use the same connection URL and credentials that were used with the VssConnection.
var buildClient = new BuildHttpClient(connection.Uri, credentials); var projectClient = new ProjectHttpClient(connection.Uri, credentials); var buildDefinition = await buildClient.GetDefinitionAsync(SettingsModel.ProjectName, SettingsModel.DefinitionId); var teamProject = await projectClient.GetProject(SettingsModel.ProjectName); await buildClient.QueueBuildAsync(new Build() { Definition = buildDefinition, Project = teamProject });
The QueueBuildAsync call triggers the build for given DefinitionId. The easiest way to get build DefinitionId is to open the build pipeline in edit mode and copy the Id from page URL. In URL it is something like edit-build-definition&id=25.
Debug plugin
Debugging the plugin is dead simple. Just install the plugin into Stream Deck device with RegisterPluginAndStartStreamDeck.ps1 PowerShell script, that comes along with the plugin template and attach the Visual Studio debugger into StreamDeck(pluginname).exe.
Summary
I haven’t yet release the plugin, because I need to implement the release pipeline support and also do some more polishing like new icons etc. After the plugin is ready you can make as many build and release pipeline buttons into Stream Deck as you need and run your production updates with single push of a button.