Very often when I am working with Releases in Visual Studio Team Services, I end up using variables for vaules in my releases. So before I go much further lets first explain the types of variables that we are going to talk about.
Global Variable – A variable that can be used across all environments in a release definition.
Environment Variable – A variable used in a specific environment in a release definition
So lets say I create a release with two builds and 4 release definitions with three environements each, Dev, QA, Prod. Lets say that I need to create a list of variables that I want to make available to four release definitions. Up until recently I have had to add then into each build or release i want to use them in. This was pretty repetitive. This is where the Variable Groups come in. Variable Groups allow me to create variables one time and use them across multiple releases. At this time the Variable Groups are only available to 2017 release definitions, but will be available for builds in the future. An example of variables I would want to share would be the System.Debug variable. I usually set it to “true” so that the builds and releases have a more verbose logging. I mainly do this as I am creating and testing the builds and releases and then set it to “false” when its ready to go live. Maybe there is a user name or database name that is shared. This is a good candidate for a variable group. So lets see how we can create and use the Variable Groups.
First off log into your VSTS or TFS 2017 and go to the Releases section. You should already have a release definition created before moving on. There is a lot of info on MSDN on how to create release definitions, so I am not getting into it here. Once you have a Release Definition, selct it and put it in Edit mode.
Once in Edit mode select the Variables option.
You will see a statement about Variable Groups with a link at the end. Click the link to manage the Variable Groups.
In the Variable Groups page, click the Variable Group button.
On the New Variable Group page, give the group a name, a description (if you want) and enter the variables. In my case I used the system.debug with a value of true. You will notice that there is a lock next to the value textbox. This allows you to create what is called a secret variable. Its an encrypted value to hide and secure the value. Click Save once complete.
Now go back to the Variables tab in the release definition and click the Variable Group button and select the new group from the dialog that pops up.Click Link once you have selected the group you want to add.
Save and Run the release to test out the new variable.
As you can see from the image above that the system.debug is set to true and the output is quite verbose.
I think this is a great new feature that I will be using in the future on my releases and will look forward to when the Build variable groups are avialable.