github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/env.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: env Stanza - Job Specification
     4  description: |-
     5    The "env" stanza configures a list of environment variables to populate the
     6    task's environment before starting.
     7  ---
     8  
     9  # `env` Stanza
    10  
    11  <Placement groups={['job', 'group', 'task', 'env']} />
    12  
    13  The `env` stanza configures a list of environment variables to populate the
    14  task's environment before starting.
    15  
    16  ```hcl
    17  job "docs" {
    18    group "example" {
    19      task "server" {
    20        env {
    21          my_key = "my-value"
    22        }
    23      }
    24    }
    25  }
    26  ```
    27  
    28  ## `env` Parameters
    29  
    30  The "parameters" for the `env` stanza can be any key-value. The keys and values
    31  are both of type `string`, but they can be specified as other types. They will
    32  automatically be converted to strings. Invalid characters such as dashes (`-`)
    33  will be converted to underscores.
    34  
    35  ## `env` Examples
    36  
    37  The following examples only show the `env` stanzas. Remember that the
    38  `env` stanza is only valid in the placements listed above.
    39  
    40  ### Coercion
    41  
    42  This example shows the different ways to specify key-value pairs. Internally,
    43  these values will be stored as their string representation. No type information
    44  is preserved.
    45  
    46  ```hcl
    47  env {
    48    key   = 1.4
    49    key   = "1.4"
    50  
    51    key = true
    52    key = "1"
    53    key = 1
    54  }
    55  ```
    56  
    57  ### Interpolation
    58  
    59  This example shows using [Nomad interpolation][interpolation] to populate
    60  environment variables.
    61  
    62  ```hcl
    63  env {
    64    NODE_CLASS = "${node.class}"
    65  }
    66  ```
    67  
    68  ### Environment variables with dots
    69  
    70  Environment variables that aren't valid HCLv2 identifiers, like ones containing `.`, require an alternative map assignment syntax.
    71  
    72  ```hcl
    73  env = {
    74    "discovery.type" = "single-node"
    75  }
    76  ```
    77  
    78  ### Dynamic Environment Variables
    79  
    80  Nomad also supports populating dynamic environment variables from data stored in
    81  HashiCorp Consul and Vault. To use this feature please see the documentation on
    82  the [`template` stanza][template-env].
    83  
    84  [interpolation]: /docs/runtime/interpolation 'Nomad interpolation'
    85  [template-env]: /docs/job-specification/template#environment-variables 'Nomad template Stanza'