Variables and objects are used throughout Continua and they enable dynamic properties and values to be used during your build process. Variables and objects are similar in the way they are called, however they differ in a few key areas which are explained below.
Expressions are the string representation of objects and variables which are used to access their values in various inputs throughout Continua CI.
Variables can be used during the build process and can be created at all levels of Continua CI. They are used to pass dynamic values into the build process. Additional information on variables can be found on the Variables page.
Variables differ from objects as they have the following properties:
Variable namespaces control where a variable exists within the Continua CI environment. Namespaces also provide variables with a scope which limits what each build can access. For example, if you create a configuration variable then only builds from that configuration can access that variable.
Environment variables are created from the server's environment variables automatically and cannot be changed. These variables can be accessed system wide by every build. Environment variables are always read-only and they can be accessed with the %Environment.MyVariableName% or %MyVariableName% syntax.
Application variables are system wide variables that every build, configuration and project can access. This means that any variable defined in the application namespace can be used anywhere in Continua CI. These are the highest variables that the user can define. Application variables are read-only at run time and they can be accessed with the %Application.MyVariableName% or %MyVariableName% syntax.
Project variables are created on a specific project and they can only be accessed by configurations and builds that belong to that project. Project variables are read-only at run time and they can be accessed with the %Project.MyVariableName% syntax.
Configuration variables are created on a specific configuration and they can only be accessed by builds that belong to that configuration. Configuration variables are read-only at run time and they can be accessed with the %Configuration.MyVariableName% syntax.
Build variables belong to a specific build however they cannot be created manually. They are used to override any of the variables listed above. Build variables can be updated at runtime - see the next section for more information on how build variables work. Build variables can be accessed with the %MyVariableName% syntax (Note that you cannot use the Build namespace prefix).
Continua CI's namespace hierarchy is designed around the idea that variables with the same name can override each other at run time. Variables will only override each other if no namespace prefix is used when accessing the variable.
For example, lets say you have 2 variables called myVariable. One of these values is defined on the configuration while the other is defined on the project.
myVariable in the configuration namespace is assigned the text "my configuration value!"
myVariable in the project namespace is assigned the text "my project value!"
During the build process, if I access myVariable with the correct namespace I will get the following values:
However, if I access myVariable without a namespace I will get the following value:
In this scenario, when accessing myVariable without a prefix, it will always return the Configuration value instead of the Project as it will return the variable in the lowest namespace it can find.
As environment, application, project and configuration variables are all read-only at run-time, their values will never change during the course of a build. All of these variables can be considered as constants at run-time. If you set the value of one of these variables during your build process, you are not actually changing the value of that variable. Instead, you are creating a new build variable with the same name which will contain the new value. This means that if you ever want to access the new value, you cannot use namespace prefixes when calling a variable in an expression.
To demonstrate changing a variable's value, lets use the myVariable example above. So lets say we have configuration variable called myVariable and its value is "my configuration value!".
In our build process we include a Set Variable Action that sets myVariable to "my new value!".
After the Set Variable action has run, if we access myVariable we will get the following values:
You can see that changing the value of myVariable did not override the value but rather created a Build Variable with the same name. Note that you cannot prefix build variables with the Build namespace.
So if you use the namespace prefix on a variable you will always get the variable's value at the start of the build, not the updated value.
Variable values can be set in a number of ways within Continua CI. (Note that by setting a variables value you are actually creating a build variable with the same name and setting its value, as explained above):
Objects are created automatically by Continua and they contain properties that relate to various aspects of Continua. For example, there are Build, Configuration and Project objects which include properties regarding the current build, configuration or project respectively. Additional information and a list of available objects can be found on the Expression Objects page.
Objects differ from variables as they have the following properties:
Expressions are the string representation of objects and variables which are used to access their values. Expressions can access both variables and objects and they are built up at design time then evaluated at run time. For example, each configuration contains a Version Format String property that is used to set the version number of each build. By default, this property uses the expression 1.0.0.$Build.BuildNumber$ (as shown below).
This expression contains two parts:
When this expression is evaluated, you will get the following results for each subsequent build:
Many inputs in Continua accept expressions as values. Most fields that accept expressions will be denoted with the icon, however you can also determine whether they are accepted by entering the '%' or '$' character. If the expression auto-complete drop down appears then the field accepts expressions.
Every input that accepts expressions includes the expression auto-complete drop down to help you determine which variables and objects can be used. This drop down will show the following object types:
Below are some examples of the expression drop down being used in the MSBuild action.
This screenshot demonstrates the objects and properties that are shown when you begin declaring an object by entering the '$' key. When the '$' key is first entered, the drop down will display all root objects that are available for the expression.
Note that child objects are denoted with the icon while properties use the icon.
As stated above, if you select an object (ie. $Build.$), all the object's properties and sub-objects will be shown in the drop down.
When you initially access variables, the root drop down will show all namespaces and every single variable that is available in all namespaces.
Note that namespaces are denoted with the icon while variables use the icon.
If you select a namespace then you will only see variables in that namespace.
The auto-complete drop down will only ever display a maximum of 10 items at a time. You can navigate through your list of elements by using the mouse wheel, the up and down arrows and the home and end keys.
Once the correct item is selected, pressing enter or tab will enter that value into the input field. Putting a '.' (full stop) at the end of the object name will display any children of that object.
Note that if the auto-complete drop down disappears, you can display it again by pressing ctrl + space.