I use Visual Studio Team Service (VSTS) as part of my DevOps process for end to end Continuous Integration (CI) and Continuous Delivery (CD). As the product grows so does the number of built in variables and whilst the documentation explains the variables you have available, understanding what the values are can be tricky. At the time of writing what is kind of strange is that the Release pipeline logs show a list of all the variable value however; the Build pipeline logs does not. In this blog I will show you an easy way of outputting the variables in the build pipeline as well as showing you where the release pipeline variable values are shown.
The list of variables used in the Build process are documented here and the list of variables used in the Release process are documented here. The only issue is that I find there are variables in the logs that are not in the documentation which suggests the documentation takes a while to get in step.
Create the Build Pipeline
Connect to your VSTS account and create a new project called Dump Variables:
Note: VSTS is constantly being updated so do not be surprised if your screens look different to mine.
I selected GIT as my source control and I am going to initialise an empty GIT repository within VSTS.
Before we configure our build pipeline we need to create a Powershell script which we will use to dump the variables. On the left side click on Code -> Files. On the right select + New -> File.
Create a new file called DumpVariables.ps1.
Paste the following code into the editor window and click the Commit button.
Get-Childitem ENV: | Format-Table Name, Value -Auto | Out-Host
We are now ready to configure our pipeline. On the left side click on Build and Release -> Build and then click on + New pipeline
By default my VSTS GIT repository is highlighted. Click Continue
It now asks you to select a template. These templates automatically add tasks into the pipeline to help speed up the process. We just need an empty one so click on the Empty process link at the top.
The first step is to select our Build Agent. This is a VM that will actually carry out the build. We can use one provided by Microsoft or we could provision our own. We will use Microsoft’s. Click on the Tasks tab, then Process and select Hosted VS2017 in the Agent queue on the right hand side. This will pick a build server running Visual Studio 2017.
The next step is to add a task to Phase 1. Each pipeline has 1 or more phases. Each phase runs 1 or more tasks on a specific agent or if required, no agent at all. If you require 2 different agents for example, you need 2 phases. Click the + on Phase 1 and in the Add Tasks window search for Powershell and select that task and click Add.
Click on the Powershell Script task to open the properties and select the DumpVariables.ps1 file by clicking on the ellipse … Then select Save & Queue -> Save to save our pipeline. We could run it from here however; I show you how to queue the build manually below.
Running our Build Pipeline
On the left pane select Build and Release -> Builds to show our build pipelines. Hover over the Dump Variables-CI build to reveal the ellipse … which you then click. Select Queue new build.
You are then presented with a screen which allows you to change some runtime characteristics. Leave them at their defaults and click Queue.
In the example below it shows the Status as in progress and next to build name a #15. The #15 represents the 15th execution of this pipeline. Click on #15 to show the execution state.
There are various tabs shown. Click on Logs to review the status of each step executed.
Click on Powershell script to open the execution log. Here we can clearly see the output from the Powershell script and the variables at build time. As an example; AGENT_BUILDDIRECTORY corresponds to Agent.BuildDirectory in the documentation.
Viewing the Release Pipeline Variables
I mentioned above that the Release pipeline already shows the variable values. I am not going to build one however; I will show you whereabouts in the logs they will be.
Navigate to your release pipeline Logs tab.
Click on the Initialize Job step to view the log and see the release variable values.