LGTM Enterprise 1.21

Setting environment variables for worker hosts

You can set an environment variable across all worker host machines in the LGTM Enterprise work pool, or on specific worker hosts.

  1. On the coordinator server, edit the lgtm-cluster-config.yml file and locate the workers block.
  2. To set environment variables for:
    • All worker hosts—add an environment property at the same level as the hosts element.
    • A specific worker host—find the required hostname subsection and add an environment property at the same level as the general element.
  3. Below the environment property, add one or more environment variables and their values. Each on its own line, in the form: <ENVIRONMENT-VARIABLE>: "<value>".

    On Linux, do not use environment variables within the value. For example, if you are setting the PATH environment variable, do not use $PATH in the value you set.

    On Windows, you can use environment variables within the value you are setting for an environment variable. However, you should make sure that the variable interpolation on the target worker host results in the expected values being used. For more information, see Using environment variables in the cluster configuration file.

    Escaping characters in setting values

    Follow the standard rules for escaping reserved characters in YAML. Typically, when setting an environment variable to a file path—using double quotes around the value—you will only ever have to escape the backslash character. You do this by adding a second backslash. For example:

    NODE_PATH: "D:\\lgtm\\tools\\ts;%NODE_PATH%"

  4. Save your changes.
  5. Generate and then deploy the files for the new configuration. See the information starting from Generating files for the configuration.

Built-in environment variables

LGTM Enterprise includes some built-in environment variables that you may find useful for configuring the work pool. For example, initially LGTM analysis has a memory limit of 6,656 MB. If this limit is exceeded, analysis fails. If some projects need more memory than this, you can set a different limit for one or more worker hosts using the environment variable LGTM_RAM (see the example in the topic on Assigning labels to workers).

Example 1—Setting environment variables for some or all machines

The extract from a cluster configuration file below includes two blocks of highlighted lines that set environment variables:

  1. The lines below the first environment label are part of the workers-host1 subsection and set values only for this worker host machine.
  2. The lines below the second environment label are part of the overall specification for worker host machines. They set values for all machines, except where they are overridden for a specific host.

This configuration sets values of ENV_VAR1 and ENV_VAR3 for all machines in the work pool. The host machine, workers-host1, has a different value for ENV_VAR1 and an additional environment variable: ENV_VAR2.

workers:

  hosts:

  - hostname: "lgtm-host"

    general: 1

    query: 1

  - hostname: "workers-host1"

    general: 2

    environment:

      ENV_VAR1: "override-default-value-on-workers-host1"

      ENV_VAR2: "value-set-only-on-workers-host1"

  temp_path: "/var/cache/lgtm/workers/"

  environment:

    ENV_VAR1: "value-to-use-on-all-workers"

    ENV_VAR3: "value-to-use-on-all-workers"

Example 2—putting tf on the PATH for TFVC checkout

To analyze projects stored in Team Foundation Version Control (TFVC), you must install the command-line client for TFS on machines that need to checkout the code (see Installing a command-line client for TFVC). After installing the client, you must set the PATH environment variable for LGTM workers to include the path to the tf file. In the example below, tf is in the /opt/TEE-CLC-14.134.0 directory.

LGTM workers are created by the LGTM application itself, and so any updates to the PATH environment variable are best defined in the cluster configuration file. In the example below, PATH is set for all machines in the work pool to ensure that when new machines are added they can also checkout code from TFVC:

workers:

  hosts:

  - hostname: "lgtm-host"

    general: 1

    query: 1

  - hostname: "workers-host1"

    general: 2

  temp_path: "/var/cache/lgtm/workers/"

  environment:

    PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/TEE-CLC-14.134.0"

Related topicsRelated topics