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 variables 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.
For more information about how to work with Kubernetes cluster and deploy it to Azure Kubernetes Service (AKS) and work with Azure Container Registry, see Kubernetes cluster for beginner.
The process of setting and displaying a variable is described in more detail below. First, I create a Command Line task to write my name, so I can recognize that part very quickly.
Then I create the second Command Line task to print out the value. Remember the variable is $(var), but since we use that with echo, we will use %var%.
Variable names are transformed to uppercase, and the characters “.” and “ “ are replaced by “_”.
For example, Agent.WorkFolder becomes AGENT_WORKFOLDER. On Windows, you access this as %AGENT_WORKFOLDER% or $env:AGENT_WORKFOLDER. On Linux and macOS you use $AGENT_WORKFOLDER.
In Ubuntu, it doesn’t include the full path with the drive letter like Windows.
But I can use the relative path to package my files from the working directory as the following. In the following example, Yarn creates a folder inside the working directory called “Build” and puts in it all the files for the package. Then I will zip it and store it on Azure DevOps Artifacts store.
If you would like to learn more about using the Build Variables in VSTS and Release Management, also working with variables, have a look at the following post: VSTS Build variables and Echo. The post describes how to see the output at any point in time while automating a process, through setting variables and displaying them during the build.
For more information about how to work with Docker, like pulling a docker image, running a docker image, and working with a container, see Docker for beginners.
The following image demonstrates how the values are displayed:
If 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.
How to send arguments to PowerShell and read them during VSTS Build
Read more about sending arguments to PowerShell and reading them during VSTS Build.
The PowerShell script will contain write-host with argument numbers:
In the PowerShell task, we send the arguments by putting each argument in double quotes with a space separator:
When we run the build, it will look like the following
Use Build variables and send them as arguments to PowerShell task which runs the PowerShell script
Read more about setting variables in scripts. Using the previous example, we will set 2 variables. Also, I made one of them secret as it holds the password:
Now, I can use them as arguments by sending each variable in double quotes with $(var) and a space separator:
For more information about how to work with Git with animation. All commands will be represented in graphical animation. E.g. git branch, git merge, git rebase, git cherry-pick and many others, see Mastering Git with animation.
When I run the build, this will display the arguments variables as the following:
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 in the VSTS build. The access here is by calling them in the PowerShell script. For example, in our scenario, I set the variable domain.username. To access it within the script, I need to transfer “.” to “_” so I have to call it as $env:domain_username.