Set Windows Service User credentials in Azure Devops

Set Windows Service User credentials in Azure Devops
Setting the login credentials for a Windows Service in Azure Devops means the service can automatically use a known login, preventing extra manual intervention on our part

In this short post, I discuss how credentials can be set for a Windows Service's User within the Azure Devops interface, making sure the application can launch automatically with a desired User without manual intervention after the install or having to add the credentials in the code or code repository. This adds on a previous post I wrote that covers how to create a release Pipeline for a Windows Service and automating installation on the target machine.    

To set a Windows user and their credentials as part of a release pipeline in Azure Devops, go into Pipelines, Releases and then find your desired Release pipeline, and then click on the Edit button.  

First go to the Variables Tab, and then add in your user's User Name and their respective password as shown in the example below. To add in extra protection for these variables within the pipeline logs and other processes that get printed in plain text, click the Lock icon to mark each variable value as a secret:

Set the username and password here. Clicking the Lock will mark a variable as a secret to protect from printing in plaintext in Azure Devops logs.

The Scopes available will be determined by the names and count of your Pipeline Stages. In my case, the existing Pipeline Stage I want to use my variables in is called 'Release', and therefore the scope I chose is Release.

Next, you will able to utilise your variables within the Installation script for your Windows service by referencing the Names. Here is what that could look like as an example:

The variables can be used as part of an Installation script like the above. Here I use the SC command to install and configure the service, and TopShelf to start it (you can choose any Installation commands you prefer)

The variables are available within the Scope or Pipeline Stage you choose and are usable in scripts and commands using "$(variablename)" .

Conclusions

Note that the Variables Tab is fully usable for other commonly used variables you may want to use within your Pipeline Tasks and not just for setting usernames and passwords.

Cover Image credits by Sq Lim on Unsplash