open-nomad/website/source/docs/job-specification/env.html.md
Alex Dadgar 9476d0b210 Small improvements to docs
This PR fixes an incorrect placement of the update stanza in the task
and also links from the env stanza into an example of using the template
block to generate dynamic environment variables.
2017-08-04 16:14:41 -07:00

1.9 KiB

layout page_title sidebar_current description
docs env Stanza - Job Specification docs-job-specification-env The "env" stanza configures a list of environment variables to populate the task's environment before starting.

env Stanza

Placement job -> group -> task -> **env**

The env stanza configures a list of environment variables to populate the task's environment before starting.

job "docs" {
  group "example" {
    task "server" {
      env {
        my_key = "my-value"
      }
    }
  }
}

env Parameters

The "parameters" for the env stanza can be any key-value. The keys and values are both of type string, but they can be specified as other types. They will automatically be converted to strings. Invalid characters such as dashes (-) will be converted to underscores.

env Examples

The following examples only show the env stanzas. Remember that the env stanza is only valid in the placements listed above.

Coercion

This example shows the different ways to specify key-value pairs. Internally, these values will be stored as their string representation. No type information is preserved.

env {
  key = "true"
  key = true

  "key" = true

  key = 1.4
  key = "1.4"
}

Interpolation

This example shows using Nomad interpolation to populate environment variables.

env {
  NODE_CLASS = "${nomad.class}"
}

Dynamic Environment Variables

Nomad also supports populating dynamic environment variables from data stored in HashiCorp Consul and Vault. To use this feature please see the documentation on the template stanza.