Creating variables and variable groups

When you are configuring your build, there might be values that you need to use more than once. It is often wise to extract these values into variables, rather than just repeating those values throughout your tasks.

Variables can be used to note down values that you do not want to have stored in source control. Values such as passwords and license keys can be safely stored as non-retrievable values when locked down using the lock symbol (see label 1 in the following screenshot). After saving the build definition, these values are encrypted and can only be used by the build that they belong to. You will no longer be able to retrieve these values and they will be automatically scrubbed from logs and other output.

To learn how to work with variables in Azure Pipelines, go through the following steps:

  1. In Azure Pipelines, you can add variables to your build definition by going to the Variables | Pipeline variables tab (see label 3 in the following screenshot). Here, you can enter them as name value, as can be seen in the following screenshot:

  1. Once defined, you can use the variables in the configuration of all tasks in all jobs of the same build. For this, you can use the following notation:
$(variableName)
  1. Finally, you can mark variables as Settable at queue time (see label 2 in the preceding screenshot), which means that their value can be changed whenever someone queues a new build. An example of a variable for which this is used is the system.debug built-in variable. When this variable is set to true, there is a verbose debug logging included in the build.

Next to your own variables, system variables are also defined. These are variables that contain information about the build that is currently running, including version numbers, agent names, build definition details, the source version, and so on. A link to the full list of system-defined variables is included at the end of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset