github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/website/source/docs/job-specification/env.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "env Stanza - Job Specification"
     4  sidebar_current: "docs-job-specification-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  <table class="table table-bordered table-striped">
    13    <tr>
    14      <th width="120">Placement</th>
    15      <td>
    16        <code>job -> group -> task -> **env**</code>
    17      </td>
    18    </tr>
    19  </table>
    20  
    21  The `env` stanza configures a list of environment variables to populate the
    22  task's environment before starting.
    23  
    24  ```hcl
    25  job "docs" {
    26    group "example" {
    27      task "server" {
    28        env {
    29          my_key = "my-value"
    30        }
    31      }
    32    }
    33  }
    34  ```
    35  
    36  ## `env` Parameters
    37  
    38  The "parameters" for the `env` stanza can be any key-value. The keys and values
    39  are both of type `string`, but they can be specified as other types. They will
    40  automatically be converted to strings. Invalid characters such as dashes (`-`)
    41  will be converted to underscores.
    42  
    43  ## `env` Examples
    44  
    45  The following examples only show the `env` stanzas. Remember that the
    46  `env` stanza is only valid in the placements listed above.
    47  
    48  ### Coercion
    49  
    50  This example shows the different ways to specify key-value pairs. Internally,
    51  these values will be stored as their string representation. No type information
    52  is preserved.
    53  
    54  ```hcl
    55  env {
    56    key   = 1.4
    57    key   = "1.4"
    58    "key" = 1.4
    59    "key" = "1.4"
    60  
    61    key = true
    62    key = "1"
    63    key = 1
    64  }
    65  ```
    66  
    67  ### Interpolation
    68  
    69  This example shows using [Nomad interpolation][interpolation] to populate
    70  environment variables.
    71  
    72  ```hcl
    73  env {
    74    NODE_CLASS = "${node.class}"
    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.html "Nomad interpolation"
    85  [template-env]: /docs/job-specification/template.html#environment-variables "Nomad template Stanza"