github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/env.mdx (about)

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