LGTM Enterprise 1.22.1

Setting environment variables for workers

You can set environment variables for workers in the cluster configuration file. You can choose to set an environment variable at three levels in the file:

  • For all workers in the work pool.
  • For all workers running on a particular host machine.
  • For groups of one or more workers running on a particular host.

To set environment variables:

  1. On the coordinator server, edit the lgtm-cluster-config.yml file and locate the workers block.
  2. To set environment variables for:
    • All workers—add an environment property at the same level as the hosts element.

    • All workers on a specific worker host—find the required hostname subsection and add an environment property at the same level as the specs element.

    • A group of one or more workers—within a hostname subsection, find the required type group and add an environment property at the same level as the copies property.

      If you want to set an environment variable for just one worker, create a new type group, with a copies value of 1 and add an environment property at the same level as the copies property (see Example 1 below).

  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.

LGTM-specific environment variables

You can use the LGTM-specific environment variables to help you configure the work pool. For example, initially LGTM analysis has a memory limit of 6 GB. If the memory requirement exceeds this, analysis fails. If some of your projects need more memory than this, you can set a different limit for some or all worker daemons using the environment variable LGTM_RAM (see the example in the topic on Enabling parallel processing).

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"

    specs:

    - type: "GENERAL"

      copies: 2

    - type: "ON_DEMAND"

      copies: 1

    - type: "QUERY"

      copies: 1

  - hostname: "workers-host1"

    environment:

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

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

    specs:

    - type: "GENERAL"

      copies: 3

    - type: "GENERAL"

      copies: 1

      labels:

      - label-for-this-worker

      environment:

        ENV_VAR1: "override-default-value-on-labeled-worker"

  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"

    specs:

    - type: "GENERAL"

      copies: 1

    - type: "QUERY"

      copies: 1

  - hostname: "workers-host1"

    specs:

    - type: "GENERAL"

      copies: 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