VSTS Build variables, Echo and arguments

Seeing the output at any point in time is very important while automating a process; for that reason we usually set variables and display them during the build. In VSTS the public variables can be defined in the Variables tab or in the running process.

 

Knowing and seeing the value of Environment variable is part of the issue described above, and is, therefore, also very important. The following links provide the lists of Build Variables and  Build definition source repositories.

 

Video You can see this video, if you would like to find more information about how to get started with Release Management and its advantages. See how to create a build definition using CI/CD Tools for VSTS Extensions (I will be using Package Extension and Publish Artifact tasks), and also using DevOps-VSTS-POC trigger in order to enable CI, all of that in order to be able to publish, share, install and query versions. You will see how to create release definition, choose an artifact and configure source for the artifact and default version. See how to create different environments or clone the existing one, in my case I am going to create QA, Preproduction and Production environment, each with one phrase and one task. See also how to configure Publish Extension task for each environment See an end-to-end continuous delivery pipeline using VSTS extension with Build and Release Management.

 

The process of setting and displaying a variable is described in more detail below.

First, I create Command Line task to write my name, so I can recognize that part very quickly.

 

Creating a Command Line task in VSTS

 

Then I create the second Command Line to print out the value, remember the variable is $(var), but since we use that with echo, – we will use %var%.

 

VSTS Command Line task - print out the value of a variable

 

Tip If you would like to learn more about using the Build Variables in VSTS and Release Management, – have a look at the following post: VSTS Build variables and Echo. The post describes how to see the output at any point of time, while automating a process, through setting variables and displaying them during the build.

 

The following image demonstrates how the values are displayed.

 

VSTS - displaying the value of a variable during the Build

p>

More InfoIf you would like to know more about Azure deployments, have a look at the post How to deploy to Azure using Team Services Release Management. The post describes how Azure deployments are made easy by using Visual Studio Team Services (VSTS) Release Management. You will see a step-by-step tutorial on how to configure and deploy to Azure in Release Management, and, moreover, how to configure an end-to-end pipeline for deploying applications on Azure.

p>

How to send argument to PowerShell and read them during VSTS Build

https://docs.microsoft.com/en-us/vsts/build-release/tasks/utility/powershell?view=vsts

The PowerShell script will contin write-host with arg number

 

VSTS Build PowerShell expose argument values

VSTS Build PowerShell expose argument values

In the PowerShell task, we send the arguments by putting each argument in double quotes with space separator

 

Send arguments to VSTS Build PowerShell script

Send arguments to VSTS Build PowerShell script

When we run the build, it will look like the following

 

Rung VSTS Build to see the arguments sent to the PowerShell script

Rung VSTS Build to see the arguments sent to the PowerShell script

 

Use Build variables and send them as arguments to PowerShell task which run PowerShell script

https://docs.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?view=vsts&tabs=batch#set-in-script

Using the previous example, we will set 2 variables, also I made the one of them secret as it hold the password as the following:

 

Set VSTS Build variables

Set VSTS Build variables

 

Now, I can use them as argument by sending each variable in double quotes with $(var) and space separator as the following:

 

Send VSTS Build variables as arguments to PowerShell VSTS Build task

Send VSTS Build variables as arguments to PowerShell VSTS Build task

 

When I run the build this will display the arguments variables as the following:

 

How VSTS Build variables will be displayed as arguments sent to the PowerShell task script

How VSTS Build variables will be displayed as arguments sent to the PowerShell task script

 

Access the VSTS Build variables without sending PowerShell arguments

Stack Overflow good related question/answer

I don’t have to send PowerShell arguments as I can access my variables that I set them in the VSTS build, the access here by calling them in the PowerShell script.

For example in our scenario, I set variable domain.username to access it within script, I need to transfer “.” to “_” so I have call it as $env:domain_username 

 

Calling VSTS build variable within PowerShell

Calling VSTS build variable within PowerShell

Share This: