/home/projects/magnet/reference/system/environment

environment

Overview

The <environment> element defines a group of variables that is passed to the system launcher as environment variables. By itself this element does not define any variable but rather contains a list of <variable> elements. The main functionality of this element is to group variables logically.

Each environment element can be assigned an identifier (through an id attribute). This ID is useful when creating different groups of environment variables to: 1) identify each environment element; and 2) to link environment elements together in a parent-child relationship (somewhat like inheritance). Under this scenario, the child environment can override variables that are defined in the parent environment.

The <environment> element can be defined in two different places in a Magnet configuration: under the root <magnet> element or within <profile> elements of a system launcher. In the first case, the environment variables mainly allow one to categorize or to define global sets of variables. In the second case, the environment variables are used by the system launcher when its specified profile is executed.

Attributes

The following lists the xml attributes of the environment element:

Name Description Required Interpolation
id An identifier for this environment variable definition. no yes
parent The identifier of this environment's parent. no yes

Child Elements

The following lists the possible child xml elements that the environment element can hold:

Name Cardinality Description
variable 1 or * Specifies a variable in the environment definition.

Rendering Operations

When an <environment> element is rendered, it performs the following operations in order:

  1. Resolves the id and the parent attributes (using variable interpolation).
  2. Renders all the <variable> child elements.

Nested Element Definitions

Variable

The <variable> element defines a name-value pair that corresponds to an environment variable.

Attributes

Name Description Required Interpolation
name The name of this variable. yes no
value The value of this variable. yes no

Rendering Operations

When a <variable> element is rendered, it performs the following operations in order:

  1. Resolves the name and value attributes (using variable interpolation).

Examples

This example shows how to define to some simple environment variables. Once the system application is started you would be able to access them using $USER_NAME or %USER_NAME% notation based on your operating system.

<magnet xmlns:magnet="http://schemas.sapia-oss.org/magnet/"
        name="EnvironmentExample1"
        description="This is a first environment example.">
...
    <environment id="base">
        <variable name="USER_NAME" value="${user.name}" />
        <variable name="USER_DIR"  value="${user.dir}" />
    </environment>
...
</magnet>