diff --git a/client/driver/driver_test.go b/client/driver/driver_test.go index 53d839e957b8..14ca00f24fae 100644 --- a/client/driver/driver_test.go +++ b/client/driver/driver_test.go @@ -209,6 +209,7 @@ func setupTaskEnv(t *testing.T, driver string) (*allocdir.TaskDir, map[string]st "NOMAD_ALLOC_INDEX": "0", "NOMAD_ALLOC_NAME": alloc.Name, "NOMAD_TASK_NAME": task.Name, + "NOMAD_GROUP_NAME": alloc.TaskGroup, "NOMAD_JOB_NAME": alloc.Job.Name, "NOMAD_DC": "dc1", "NOMAD_REGION": "global", diff --git a/client/driver/env/env.go b/client/driver/env/env.go index 71bee9e440b6..9e63accbc0a9 100644 --- a/client/driver/env/env.go +++ b/client/driver/env/env.go @@ -44,6 +44,9 @@ const ( // TaskName is the environment variable for passing the task name. TaskName = "NOMAD_TASK_NAME" + // GroupName is the environment variable for passing the task group name. + GroupName = "NOMAD_GROUP_NAME" + // JobName is the environment variable for passing the job name. JobName = "NOMAD_JOB_NAME" @@ -208,6 +211,7 @@ type Builder struct { region string allocId string allocName string + groupName string vaultToken string injectVaultToken bool jobName string @@ -277,6 +281,9 @@ func (b *Builder) Build() *TaskEnv { if b.allocName != "" { envMap[AllocName] = b.allocName } + if b.groupName != "" { + envMap[GroupName] = b.groupName + } if b.allocIndex != -1 { envMap[AllocIndex] = strconv.Itoa(b.allocIndex) } @@ -380,6 +387,7 @@ func (b *Builder) setTask(task *structs.Task) *Builder { func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder { b.allocId = alloc.ID b.allocName = alloc.Name + b.groupName = alloc.TaskGroup b.allocIndex = int(alloc.Index()) b.jobName = alloc.Job.Name diff --git a/client/driver/env/env_test.go b/client/driver/env/env_test.go index ce5262ebd48f..1f288997db59 100644 --- a/client/driver/env/env_test.go +++ b/client/driver/env/env_test.go @@ -181,6 +181,7 @@ func TestEnvironment_AsList(t *testing.T) { "NOMAD_HOST_PORT_http=80", "NOMAD_HOST_PORT_https=8080", "NOMAD_TASK_NAME=web", + "NOMAD_GROUP_NAME=web", "NOMAD_ADDR_ssh_other=192.168.0.100:1234", "NOMAD_ADDR_ssh_ssh=192.168.0.100:22", "NOMAD_IP_ssh_other=192.168.0.100", diff --git a/website/source/docs/runtime/_envvars.html.md.erb b/website/source/docs/runtime/_envvars.html.md.erb index f8267fa7f985..37f8bcd0c19d 100644 --- a/website/source/docs/runtime/_envvars.html.md.erb +++ b/website/source/docs/runtime/_envvars.html.md.erb @@ -51,6 +51,10 @@ NOMAD_TASK_NAME Task's name + + NOMAD_GROUP_NAME + Group's name + NOMAD_JOB_NAME Job's name diff --git a/website/source/docs/runtime/environment.html.md.erb b/website/source/docs/runtime/environment.html.md.erb index 3a0fbde08396..a7c3e743fa3d 100644 --- a/website/source/docs/runtime/environment.html.md.erb +++ b/website/source/docs/runtime/environment.html.md.erb @@ -23,11 +23,11 @@ environment variable names such as `NOMAD_ADDR__