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:
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 are available within the Scope or Pipeline Stage you choose and are usable in scripts and commands using "$(variablename)" .
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