Files
nomad/website/content/docs/job-specification/env.mdx
Aimee Ukasick 986f3c727a Docs: SEO job spec section (#25612)
* action page

* change all page_title fields

* update title

* constraint through migrate pages

* update page title and heading to use sentence case

* fix front matter description

* Apply suggestions from code review

Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>

---------

Co-authored-by: Jeff Boruszak <104028618+boruszak@users.noreply.github.com>
2025-05-19 09:02:07 -05:00

85 lines
2.0 KiB
Plaintext

---
layout: docs
page_title: env block in the job specification
description: |-
Configure environment variables in the `env` block of the Nomad job specification.
---
# `env` block in the job specification
<Placement groups={['job', 'group', 'task', 'env']} />
The `env` block configures a list of environment variables to populate the
task's environment before starting.
```hcl
job "docs" {
group "example" {
task "server" {
env {
my_key = "my-value"
}
}
}
}
```
## Parameters
The "parameters" for the `env` block 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.
## Examples
The following examples only show the `env` blocks. Remember that the
`env` block 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.
```hcl
env {
key = 1.4
key = "1.4"
key = true
key = "1"
key = 1
}
```
### Interpolation
This example shows using [Nomad interpolation][interpolation] to populate
environment variables.
```hcl
env {
NODE_CLASS = "${node.class}"
}
```
### Environment variables with dots
Environment variables that aren't valid HCLv2 identifiers, like ones containing `.`, require an alternative map assignment syntax.
```hcl
env = {
"discovery.type" = "single-node"
}
```
### 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` block][template-env].
[interpolation]: /nomad/docs/runtime/interpolation 'Nomad interpolation'
[template-env]: /nomad/docs/job-specification/template#environment-variables 'Nomad template Block'